-4

I wrote the following function:

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

But it keeps saying enter_digit is not defined!

What am I doing wrong? I using the latest Python available.

This is the actual code that I'm running:

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)

But it still says not defined?

Zebra
  • 23
  • 2
  • 6
  • See the edits I made to your code. Note that `=` `!=` `==` ;-). And indentation matters in Python. – wgwz May 14 '16 at 21:01
  • 4
    Please don't make edits to answer the question. – ayhan May 14 '16 at 21:05
  • I rolled back changes to the code. – Valentin Lorentz May 14 '16 at 22:12
  • So many basic errors there. – Jongware May 14 '16 at 22:38
  • Note to OP: Don't feel bad about basic errors. We have all been there. – wgwz May 15 '16 at 01:48
  • I'm aware of the errors of a and b not having "" or not being defined. I just wrote it like that because, I was using a tablet when I asked this question and I'm a slow typer with it . Thank you though. I can't believe I didn't notice. – Zebra May 15 '16 at 05:09
  • Possible duplicate of [Python: NameError: global name 'foobar' is not defined](http://stackoverflow.com/questions/4068785/python-nameerror-global-name-foobar-is-not-defined) – Amin Alaee May 15 '16 at 07:29
  • 1
    @wgwz: I was referring to the fact that those basic syntax errors made it hard to answer the actual question! How do we know which of these errors were also present in the original program and therefore caused the problem? – Jongware May 16 '16 at 14:27
  • @RadLexus you are right, i just wanted to add some encouragement :) – wgwz May 16 '16 at 19:39

2 Answers2

1

Try this:

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

main_menu(1)

The code needed to be indented correctly. Keep in mind that if variables a, hello and b are not defined, the code will not run. If they are not variables, and you want the code to print "hello", "a" and "b", then add quotation marks.

When you were checking the variable value, you were assigning the value, not checking, hence the use of ==.

techydesigner
  • 1,681
  • 2
  • 19
  • 28
0

The below one will work, its just indentation

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)
Al Foиce ѫ
  • 4,195
  • 12
  • 39
  • 49
Sriram
  • 1