关于第五课改进小游戏题目的代码无法进入正确答案
你好老师,我按照小甲鱼老师的讲解,完成了课后练习的,但是无论输入哪个数字,都进不了正确答案,请问代码哪里需要修改
import random
time = 9
secret = random.randint(1,10)
print('----------------------我爱工作室----------------------')
guess = 0
print("猜一下我现在心里想的是哪个数字:",end=" ")
while (guess != secret) and (time > 0 ):
temp = input()
while not temp.isdigit():
temp = input("抱歉,您输入有误,请输入整数:")
gusee = int(temp)
time = time - 1
if guess == secret:
print("哇,你是我心里的蛔虫吗?!")
print("哼,猜中了也没有奖励!")
else:
if gusee > secret:
print("哥,大了大了~~~")
else:
print("嘿,小了小了~~~")
if time > 0:
print("再试一次吧:",end=" ")
else:
print("机会用光啦")
print("游戏结束")
因为你第 11行、17 行代码的 guess 拼写成了 gusee 导致的错误
将两个变量名为 gusee 改为 guess 即可
第11行,单词拼错了
guess
import random
time = 9
secret = random.randint(1,10)
print('----------------------我爱工作室----------------------')
guess = 0
print("猜一下我现在心里想的是哪个数字:",end=" ")
while (guess != secret) and (time > 0 ):
temp = input()
while not temp.isdigit():
temp = input("抱歉,您输入有误,请输入整数:")
guess = int(temp)
time = time - 1
if guess == secret:
print("哇,你是我心里的蛔虫吗?!")
print("哼,猜中了也没有奖励!")
else:
if guess > secret:
print("哥,大了大了~~~")
else:
print("嘿,小了小了~~~")
if time > 0:
print("再试一次吧:",end=" ")
else:
print("机会用光啦")
print("游戏结束")
谢两位老师
页:
[1]