繁体   English   中英

如何解决 NameError: name 'randomResponce' is not defined

[英]How do I solve the NameError: name 'randomResponce' is not defined

这是有错误的代码:

print("Through 1-10 write a number that is going to represent how far you should throw the ball for " + playerCMD4 + "to catch") ; sleep(float(speed))
                    playerNumberCMD = raw_input()
                    import random
                    def allResponses(arg1):
                            allResponses = arg1
                    allResponses = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
                    def randomResponse(arg1):
                            randomResponse = arg1
                    randomResponse = random.choice(allResponses)
                    if randomResponce == playerNumberCMD:
                            print(playerCMD4 + " caught the ball.") ; sleep(float(speed))

我得到的错误是:Traceback(最近一次通话最后一次):

  File "classref3.py", line 3, in <module>
    class Dog:
  File "classref3.py", line 50, in Dog
    if randomResponce == playerNumberCMD:
NameError: name 'randomResponce' is not defined

Def不是 go 的正确方法还是别的什么?

由于错误状态,您尚未定义变量“randomResponce”。

如果您查看您认为已定义变量的上一行,则您已定义“randomResponse”。 注意不同的拼写。 拼写必须相同。

我还要注意不要在同一脚本中对变量和 function 使用相同的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM