加了一行测试代码,你可以测试一下# 一款猜数字的小游戏
from random import randint
try_time = 1
guess_number = randint(1, 100)
while True:
print('此时的guess_number为:',guess_number)#测试代码
number = int(input("请输入一个数字,十次没猜中后记为失败."))
if number > guess_number:
print("抱歉,你输入的数字大于所指定的值。")
try_time += 1
elif number < guess_number:
print("抱歉,你输入的数字有些小了")
try_time += 1
else:
print("恭喜你,猜中了,你可真是个小机灵鬼。")
if try_time == 10 or number == guess_number:
msg = input("你要重来吗?输入是重新开始。")
if msg == '是':
try_time += 1
guess_number = randint(1, 100)
else:
print("拜拜了您内。")
break
|