gzj137070928 发表于 2020-9-30 09:20:46

猜年龄游戏升级版

猜年龄游戏升级版:任性玩
先限定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!')
'''

heidern0612 发表于 2020-9-30 09:30:38

嗯,我写了个这个,也挺好玩的。{:10_297:}

戳我前进

gzj137070928 发表于 2020-9-30 10:03:24

heidern0612 发表于 2020-9-30 09:30
嗯,我写了个这个,也挺好玩的。

戳我前进

{:5_91:}{:5_95:}
页: [1]
查看完整版本: 猜年龄游戏升级版