马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
猜年龄游戏升级版:任性玩
先限定5次机会,并给出相应的偏大偏小提示,后面添加条件5次之后是否继续猜
age = 33
count = 5
while count > 0:
print('您有{_count}次猜测机会!'.format(_count=count))
guess_age = int(input('guess age:'))
if guess_age == age:
print('Yes,you got it.')
break
elif guess_age > age:
print('Think smaller!')
else:
print('Think bigger!')
count = count - 1 # count - =1也可以
if count == 0:
continue_guess = input('Do you want to countinue trying? Y or N\n')
if continue_guess == 'Y':
count = 5
else:
print('Byebye')
else:
print('Game over!')
'''改成for循环
for n in range(5):
print('您有{_count}次猜测机会!'.format(_count=count))
guess_age = int(input('guess age:'))
if guess_age == age:
print('Yes,you got it.')
break
elif guess_age > age:
print('Think smaller!')
else:
print('Think bigger!')
count = count - 1
else:print('Game over!')
'''
|