名称错误未定义

时间:2016-05-14 20:56:35

标签: python nameerror

我写了以下函数:

def main_menu(enter_digit):
    Print(a)
    Print(b)
    if enter_digit = 1:
        Print(hello)
        main_menu(1)

但它一直说enter_digit未定义!

我做错了什么?我使用最新的Python。

这是我正在运行的实际代码:

def Main_menu(Digit):
    print("a - Objective_1")
    print("b - Objective_2")
    print("c - Objective_3")
    print("d - Objective_4")
    print("e - Objective_5")
    print("f - Objective_6")
    print("g - Objective_7")  
    print("h - Exist")
    if Digit == 1:
        print("hello")
        Main_menu(1)

但它仍然没有定义?

2 个答案:

答案 0 :(得分:1)

试试这个:

AudioInputStream

代码需要正确缩进。请记住,如果未定义变量a,hello和b,则代码将不会运行。如果它们不是变量,并且您希望代码打印“hello”,“a”和“b”,则添加引号。

当您检查变量值时,您分配的是值,而不是检查,因此使用==。

答案 1 :(得分:0)

下面的一个会工作,它只是缩进

def Main_menu(Digit):
    print("a - Objective_1")
    print("b - Objective_2")
    print("c - Objective_3")
    print("d - Objective_4")
    print("e - Objective_5")
    print("f - Objective_6")
    print("g - Objective_7")  
    print("h - Exist")
    if Digit == 1:
        print("hello")
Main_menu(1)
相关问题