Guess the age of the game:
Game rules:
- Allow users to try up to 3 times
- After each attempt 3 times, if not guessed right, ask the user whether still want to continue to play, if the answer Y or Y, continue to let it guess 3 times, to reciprocate, if answer n or N, quit the program
- How to guess right, just quit.
1Age=182Count=True3 whileCount:4 5 forIinchRange (3):6Guess_age=int (Input ('guess how old my age is:'))7 ifGuess_age <Age :8 Print('guess small, go to Dali.')9 elifGuess_age >Age :Ten Print('big guess, go to Little Li Chai.') One Else: A Print('Congratulations, you guessed it.') - exit () - Else: theAns=input ('excessive number of errors, whether to continue: y/n-->:') - ifAns = ='Y' orAns = ='y': - Continue - elifAns = ='N' orAns = ='N': +Count =False - Else: + Print('input error, resulting in direct exit') ACount = False
View Code
Python guessing the age of the game