我也是甲鱼 发表于 2016-9-14 10:53:07

写完代码试运行时报错

-----欢迎来到游戏-----
猜下数字呗:Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\新建文件夹 (2)\game.py", line 7, in <module>
    while(gusee != secret)and(times > 0):
NameError: name 'gusee' is not defined

我也是甲鱼 发表于 2016-9-14 10:53:51

本帖最后由 我也是甲鱼 于 2016-9-14 10:56 编辑

import random
times = 3
secret = random.randint(1,10)
print('-----欢迎来到游戏-----')
guess = 0
print("猜下数字呗:",end="")
while(gusee != secret)and(times > 0):
    temp = input()
    while not temp.isdigit():
      temp = input("抱歉,你输入错误,请输入一个整数:")
    guess = int(temp)
    times = times - 1
    if guess == secret:
      print("恭喜你,猜中啦")
    else:
      if guess > secret:
            print("数字大了哦")
      else:
            print("数字小拉")
      if times > 0:
            print("再试试吧,你一共有三次机会哦:",end="")
      else:
            print("抱歉,机会用光啦")
print("游戏结束!")

c3011323 发表于 2016-9-14 11:16:42

(gusee != secret)   貌似 是说 这个错了

SixPy 发表于 2016-9-14 11:29:42

guess = 0
gusee != secret

一抹心尘 发表于 2020-10-26 17:04:18

粗心大意 ,代码第7行把guess写成了 gusee
页: [1]
查看完整版本: 写完代码试运行时报错