确实是我画蛇添足了,谢谢大佬。
#猜数字游戏
print("--猜数字--")
import random
secret = random.randint(1,20)
secret = 8
times = input("你觉得自己几次能猜中呢:")
times = int(times)
temp = input("猜猜我心中想的数字是:\n")
guess = int(temp)
round = 1
while round < times:
if guess == secret:
print("我草,这都行!")
break
elif guess > secret:
print("太大了!")
else:
print("太小了!")
temp = input("第"+str(round)+"轮没猜中,请重新输入吧:")
guess = int(temp)
round +=1
else:
if guess == secret:
print("我草,这都行!")
else:
print("太遗憾了,次数用完了也没猜对!")
print("我心中想的数字是:"+str(secret))
print("GAME OVER!")
【 在 ToSimplicity 的大作中提到: 】
: 可以用while ... else ...
: round > times 时,没有猜中可言
--
FROM 111.203.202.*