我有一段python代码,我已经定义了对象,但它无法识别



这是代码

def startgame ():
    print ("welcome to the game type start to continue")
print
prompt_sta ()
#the error is here
def prompt_sta ():
    prompt_sta = raw_input ("Enter a command: ")

startgame ()
prompt_sta

将函数定义移动到文件的顶部。 必须先定义它,然后才能使用它。 在发布的代码中,当您尝试调用prompt_sta时,尚未定义它。

另请注意,您在底部的使用缺少括号以作为正确的调用。 这种说法没有任何作用。

def prompt_sta ():
    prompt_sta = raw_input ("Enter a command: ")
def startgame ():
    print ("Welcome to the game!  Type start to continue")
print
prompt_sta()
# The error is here
startgame()
prompt_sta()

相关内容

最新更新