-2
menu()

if key==1:
    print(display)    

def menu():
    while key:
        print("1- Display all data")
        print("2- Process data")
        print("press enter to Exit")
        key=input("What would u like to do?")
        return key

I'm keep on getting an error that menu is not defined.

Taku
  • 31,927
  • 11
  • 74
  • 85
Hamza
  • 1
  • 4
  • Have you considered defining `menu` *before* trying to call it? – jonrsharpe Jan 23 '16 at 12:25
  • @jonrsharpe This is my modified code – Hamza Jan 23 '16 at 12:27
  • def menu(): while key: print("1- Display all data") print("2- Process data") print("press enter to Exit") key=input("What would u like to do?") return key menu() if key==1: print(display) – Hamza Jan 23 '16 at 12:28
  • 1
    ...what? What is? Please give a [mcve] with correct formatting in the question itself. – jonrsharpe Jan 23 '16 at 12:28
  • @jonrsharpe I tried what you said and now it says UnboundLocalError: local variable 'key' referenced before assignment. – Hamza Jan 23 '16 at 12:33
  • Of course it does, for *exactly the reason the error message tells you*. – jonrsharpe Jan 23 '16 at 12:34
  • Possible duplicate of [function is not defined error in Python](http://stackoverflow.com/questions/5986860/function-is-not-defined-error-in-python) – user4098326 Jan 23 '16 at 12:44

1 Answers1

0

You're attempting to call menu before the actual definition of menu. Simply move all definitions above the block of code you use to call them, and you'll be fine.

Benjamin James Drury
  • 2,353
  • 1
  • 14
  • 27