#333333; line-height: 1.5em !important;”>I learned how to use the while function in python thanks to this WSQ. Its easier to do a “while” than a lot of “ifs”, thats why i made my code with a single while function.
#333333; line-height: 1.5em !important;”>I used this links that showed me how to get a random number and how to use the while function in python.
#333333; line-height: 1.5em !important;”>#4c93cb; text-decoration: none;” href=”http://stackoverflow.com/questions/5555712/generate-a-random-number”>http://stackoverflow.com/questions/5555712/generate-a-random-number
#333333; line-height: 1.5em !important;”>#4c93cb; text-decoration: none;” href=”http://www.tutorialspoint.com/python/python_loops.htm”>http://www.tutorialspoint.com/python/python_loops.htm
#333333; line-height: 1.5em !important;”>Here’s my code:
#333333; line-height: 1.5em !important;”>#8cbf99; text-decoration: none; font-family: ‘Helvetica Neue’, Helvetica, Arial, sans-serif; padding: 3px; font-size: 1em; background-repeat: repeat-x;” href=”http://gilrg18.withknown.com/tag/Gilberto” rel=”tag”>#Gilberto Rogel García a01630171
#333333; line-height: 1.5em !important;”>import random
#333333; line-height: 1.5em !important;”>value= random.randint(1,100)
#333333; line-height: 1.5em !important;”>tries=0
#333333; line-height: 1.5em !important;”>num= int(input(“Guess a number from 1 to 100:”))
#333333; line-height: 1.5em !important;”>while num != value: ###the while funtion starts here, i put “!=” so when the number is different from value the while function will take place.
#333333; line-height: 1.5em !important;”>if num>value :
#333333; line-height: 1.5em !important;”>print (num, “is too high”)
#333333; line-height: 1.5em !important;”>num= int(input(“Try again:”))
#333333; line-height: 1.5em !important;”>tries=tries+1
#333333; line-height: 1.5em !important;”>elif num<value :
#333333; line-height: 1.5em !important;”>print (num, “is too low”)
#333333; line-height: 1.5em !important;”>num= int(input(“Try again:”))
#333333; line-height: 1.5em !important;”>tries= tries+1
#333333; line-height: 1.5em !important;”>tries= tries +1 ###here is where the while function ends, when the number is equal to value.
#333333; line-height: 1.5em !important;”>print(“Congratulations!, The right number is”,value)
#333333; line-height: 1.5em !important;”>print(“It took you” ,tries, “tries to win”)
#333333; line-height: 1.5em !important;”>#8cbf99; text-decoration: none; font-family: ‘Helvetica Neue’, Helvetica, Arial, sans-serif; padding: 3px; font-size: 1em; background-repeat: repeat-x;” href=”http://gilrg18.withknown.com/tag/TC1014″ rel=”tag”>#TC1014 #8cbf99; text-decoration: none; font-family: ‘Helvetica Neue’, Helvetica, Arial, sans-serif; padding: 3px; font-size: 1em; background-repeat: repeat-x;” href=”http://gilrg18.withknown.com/tag/WSQ06″ rel=”tag”>#WSQ06