猜年龄游戏
猜年龄的互动游戏,限定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]