本帖最后由 yexing 于 2020-3-4 10:58 编辑
你这个程序有bug啊... guess 和 cishu 没初始化from random import randint
daan = random.randint(8,8) #应该是直接randint()
print("猜猜我心里想的什么数: ", end = "")
while guess != daan: #guess is not defined
guess = int(input())
if guess == daan:
print('我日,你竟然猜对了')
elif cishu > 0: #cishu is not defined
print("再试一次吧:",end="")
else:
print("小了!")
print("游戏结束!!")
真要压缩还是得这样压 from random import randint
daan, guess, cishu = randint(8,8), 0, 3 #randint()里的参数有点迷
print("猜猜我心里想的什么数: ", end = "")
while (guess != daan) and (cishu > 0):
guess = int(input())
if guess == daan:
print('我日,你竟然猜对了\n游戏结束!!')
else:
cishu -= 1
print("机会用完了\n游戏结束!!") if cishu <= 0 else print("再试一次吧:", end="")
|