我得到的是“名称错误:cont1()未定义”,即使它以前已定义

2024-06-16 09:39:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python和一个名为Replit的IDE。 cont1在调用之前已定义

if roomchoose=="2":
    sleep(1)
    print("You open the door on the right, only to find a run down kitchen.")
    sleep(1)
    print("You try the door on the left, and find a small bedroom, the sword and shield lay neatly on the bed")
    cont1() 

在cont1()上,它告诉我它没有定义,但是,我已经定义了它(在上面调用它)

def cont1():
    inventory.append("Sword. Shield")
    sleep(1)
    print("Sword (3dmg) added to inventory. Shield (3 defense) added to inventory")
    sleep(1)

这就是它被定义的地方,我做的和另一个函数完全一样,它似乎在工作。所以,我不确定是IDE让人讨厌,还是这个特定函数有错误


Tags: andthetoyou定义onsleepfind