Python 如何解决名称错误:name';随机响应';没有定义
这是出现错误的代码:Python 如何解决名称错误:name';随机响应';没有定义,python,nameerror,Python,Nameerror,这是出现错误的代码: 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
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))
我得到的错误是:
回溯(最近一次呼叫最后一次):
文件“classref3.py”,第3行,在
班犬:
文件“classref3.py”,第50行,在Dog中
如果RandomResponse==PlayerNumber cmd:
NameError:未定义名称“RandomResponse”
Def
不是正确的方法,还是其他原因?因为错误表明您没有定义变量“randomResponse”
如果您查看上一行,您认为您已经定义了变量,那么您已经定义了“randomResponse”。注意不同的拼写。拼写必须相同
我还要提醒大家,不要在同一个脚本中对变量和函数使用相同的名称
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