Python=在DEF中

2024-09-24 08:38:31 发布

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

代码:

print("Starting...")

def test():
    notare = input()
    bote()

def bote():
    if notare == "a":
        print("b")
    else:
        print("c")

test()

错误:

Traceback (most recent call last):
  File "test.py", line 13, in <module>
    test()
  File "test.py", line 5, in test
    bote()
  File "test.py", line 8, in bote
    if notare == "a":
NameError: name 'notare' is not defined

Tags: 代码inpytestinputifdef错误
1条回答
网友
1楼 · 发布于 2024-09-24 08:38:31

python不会知道函数存在。。。 Python以有序的方式执行。。。这意味着您必须先声明函数,然后才能调用它

所以,为了你的问题。。 尝试将函数移到调用它的函数上方

像这样

print("Starting...")

def bote(notare):
    if notare == "a":
        print("b")
    else:
        print("c")

def test():
    notare = input()
    bote(notare)


test()

相关问题 更多 >