#333333; font-family: Georgia, ‘Times New Roman’, Times, serif; font-size: 16.7999992370605px; line-height: 25.1999988555908px;”>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; font-family: Georgia, ‘Times New Roman’, Times, serif; font-size: 16.7999992370605px; line-height: 25.1999988555908px;”>I used this links that showed me how to get a random number and how to use the while function in python:
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif; font-size: 16.7999992370605px; line-height: 25.1999988555908px;”>http:/
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif; font-size: 16.7999992370605px; line-height: 25.1999988555908px;”>http:/
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”>import random
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”>value= random.randint(1,100)
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”>tries=0
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”>num= int(input(“Guess a number from 1 to 100:”))
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”>while num != value:
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”> if num>value :
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”> print (num, “is too high”)
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”> num= int(input(“Try again:”))
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”> tries=tries+1
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”> elif num<value :
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”> print (num, “is too low”)
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”> num= int(input(“Try again:”))
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”> tries= tries+1
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”>tries= tries +1
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”>print(“Congratulations!, The right number is”,value)
#333333; font-family: Georgia, ‘Times New Roman’, Times, serif;”>print(“It took you” ,tries, “tries to win”)
Untitled by Gilberto Rogel García is licensed under a Creative Commons Attribution 4.0 International License.