我是 python 新手,一直在练习类和方法。当我运行包含以下代码的脚本时,我收到错误“NameError:未定义全局名称“nameCheck”。” 我该如何解决?提前致谢。
class game(object):
def play():
name = input("What's your name, my friend? ")
check = nameCheck(name)
if check == 1:
print ("Hello %r " %(name))
else:
print ("Sorry, I can't print your name because you don't have one!")
def nameCheck(name):
if name == "":
print("I can't believe you have no name!")
return 0
else:
print("%s is a nice name!" %name)
return 1
game.play()
Python“NameError:未定义全局名称”nameCheck“。”</p>