1

I am creating a menu but i have come across an error an would like some help as i don't know what is wrong or how to fix it, the piece of code says i am putting an argument in but i have not entered an argument.

class menu(object):

    def print_menu():
    # menu options    
        print "Main Menu:"
        print "Start"
        print "Quit"

    def user_menu():
    # users input
        menu_choice = raw_input('> ')

        if menu_choice == 'start':
            start()
        #does nothing as of yet
        elif menu_choice == 'quit':
            raise SystemExit

def start():
    pass

#initialising main menu
main = menu()

def start_up()

    main.print_menu()
    #first attempt
    main.user_menu()
    #second attempt
    main.user_menu()
    #third attempt
    main.user_menu()
    # start again to show the menu options
    start_up()


start_up()

please help, this is the traceback error most recent call the occurs in the console when i run the script

Traceback (most recent call last):
 File "Engine.py", line 38, in <module>
    start_up()
  File "Engine.py", line 27, in start_up
   main.print_menu()
TypeError: print_menu() takes no arguments (1 given)

1 Answer 1

1

You forgot to add self as an argument.

So it has to look like this:

class menu(object):

    def print_menu(self):
        # menu options    
        print "Main Menu:"
        print "Start"
        print "Quit"

    def user_menu(self):
        # users input
        menu_choice = raw_input('> ')

        if menu_choice == 'start':
            start()
        #does nothing as of yet
        elif menu_choice == 'quit':
            raise SystemExit

Also, I am not sure if using class here is needed. If I were you, I would get rid of the menu class and use just leave those methods.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you!!! i am new to classes so it seems i have careless with the most simple mistake
oh the class here is need for the project i am doing

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.