python used while writing guess ages games

demand:

  Users have an opportunity to guess the age of three games, each one will guess the appropriate prompt to inform the user should go big or small dot dot guess guess, exhausted after three chances, three chances to choose and start again.

Ideas:

  First, the definition of an initial age of 25 and the number of initial 0, then guessing every time, the number of plus 1, while suggesting guess age is too small or too big, I guess when you exit the game, when the number of times equal to 3, the user is prompted to start again .

code show as below:

 1 age_of_fww = 25
 2 count = 0
 3 while count < 3:
 4     guess_age = int(input("guess_age:"))
 5     if guess_age == age_of_fww:
 6         print("yes! you got it")
 7         break
 8     elif guess_age < age_of_fww:
 9         print("think bigger!")
10     else:
11         print("think smaller!")
12     count+=1
13     if(count == 3):
14         continue_confirm = input("do you want to keep guessing(y/n)")
15         if continue_confirm == 'y':
16             count = 0

 

Guess you like

Origin www.cnblogs.com/xifeng59/p/11628299.html