gzj137070928 发表于 2020-9-30 09:17:32

猜年龄游戏

猜年龄的互动游戏,限定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也可以
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!')
'''
页: [1]
查看完整版本: 猜年龄游戏