这是有错误的代码:
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))
我得到的错误是: 追溯(最近一次通话):
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
是不正确的方法还是其他方法?
答案 0 :(得分:0)
由于错误状态,您尚未定义变量“ randomResponce”。
如果您认为定义了变量的前一行,则定义了“ randomResponse”。请注意不同的拼写。拼写必须相同。
我还要注意不要在同一脚本中为变量和函数使用相同的名称。