#TC1014<\/a> #WSQ06<\/a> #awesome<\/a><\/strong><\/p>\n this time the program has to pick a number at random from 1 to 100 and ask the user to gues the number, after the user makes a guess the program will give hints if the number the user gave is too high or too low in relation with the number picked by the program.<\/strong><\/p>\n for the program to choose a number at random you can use the random function of python:<\/strong><\/p>\n import random<\/strong><\/p>\n and give a variable for the value, if we want a number from 1 to 100 set the range (1,101) because the range goes from the first number to the number before the last.<\/strong><\/p>\n import random<\/strong><\/p>\n x = random.randrange(1,101)<\/strong><\/p>\n with that you should get a random number between 1 and 100. now ask the user for an integer to continue with the program and open a “while” loop so the program doesn’t stop until the number from the user is the same as the random:<\/strong><\/p>\n y = int(input(“number”))<\/strong><\/p>\n while y != x: ——- (“!=” means not equal to)<\/strong><\/p>\n and to give the hints to help the user use if statements and ask for anothe number:<\/strong><\/p>\n if y > x:<\/strong><\/p>\n print (“too high”)<\/strong><\/p>\n y = int(input(“again”))<\/strong><\/p>\n make another for a number below the random. when the user hits the number tell the program to print it:<\/strong><\/p>\n print (“correct it is “,y)<\/strong><\/p>\n if you want to add a counter to know how many times you tried make a variable with 0 and do this inside the while loop:<\/strong><\/p>\n z = 0<\/strong><\/p>\n while y != x:<\/strong><\/p>\n z += 1<\/strong><\/p>\n and tell the program to print the result at the end:<\/strong><\/p>\n print (z)<\/strong><\/p>\n my code is in github:<\/strong><\/p>\n https:\/ this video helped me to understand loops in python:<\/strong><\/p>\n https:\/ question- how do I tell the program to run again after completing the condition of the while loop?<\/strong><\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":" #TC1014 #WSQ06 #awesomethis time the program has to pick a number at random from 1 to 100 and ask the user to gues the number, after the user makes a guess the program will give hints if the number the user gave is too high or too low in relat… Continue reading