猜年龄游戏升级版
猜年龄游戏升级版:任性玩
先限定5次机会,并给出相应的偏大偏小提示,后面添加条件5次之后是否继续猜
1 age = 33 2 count = 5 3 while count > 0: 4 print('您有{_count}次猜测机会!'.format(_count=count)) 5 guess_age = int(input('guess age:')) 6 if guess_age == age: 7 print('Yes,you got it.') 8 break 9 elif guess_age > age: 10 print('Think smaller!') 11 else: 12 print('Think bigger!') 13 count = count - 1 # count - =1也可以 14 if count == 0: 15 continue_guess = input('Do you want to countinue trying? Y or N\n') 16 if continue_guess == 'Y': 17 count = 5 18 else: 19 print('Byebye') 20 else: 21 print('Game over!') 22 '''改成for循环 23 for n in range(5): 24 print('您有{_count}次猜测机会!'.format(_count=count)) 25 guess_age = int(input('guess age:')) 26 if guess_age == age: 27 print('Yes,you got it.') 28 break 29 elif guess_age > age: 30 print('Think smaller!') 31 else: 32 print('Think bigger!') 33 count = count - 1 34 else:print('Game over!') 35 '''