0

I'm trying to create a function in python that outputs a menu like this:

MENU

p) Play the matching penny game

q) Quit

What I've tried...

def display_menu(): print "###MENU###" print "p) Play the matching penny game" print "q) Quit" 

I want to call the function in a script and have the menu displayed, but it doesn't display in the shell nor does it throw an error. How do I go about doing this?

3
  • as long as you call the function >>> display_menu() it should work. Commented Dec 14, 2015 at 2:49
  • 1
    Show us your script, to see how did you call a function. I am afraid there is typo. Commented Dec 14, 2015 at 2:56
  • This is very basic stuff that is covered in any decent python tutorial. You are better off just slugging through a tutorial than letting yourself get bogged down trying to write code too early. Commented Dec 14, 2015 at 3:31

4 Answers 4

1

I guess you forgot to call the display_menu function. Try this:

def display_menu(): print "MENU".center(10, "#") print "p) Play the matching penny game" print "q) Quit" if __name__ == "__main__": display_menu() 
Sign up to request clarification or add additional context in comments.

Comments

0
def display_menu(): print "###MENU###" print "p) Play the matching penny game" print "q) Quit" display_menu() # call the function 

You have to actually call the function in order for it to run.

Comments

0

you probably need parentheses around your text..

def display_menu(): print ("###MENU###") print ("p) Play the matching penny game") print ("q) Quit") display_menu() 

1 Comment

This was my problem, I'm new to python hahah - thank you so much!
0

The function you wrote is 100% fine for what you want. The problem is that you aren't calling it at all during execution. If your program is going to be complex, I'd suggest creating a main function where everything major takes place, the heart of your program, and calling that via:

if __name__ == "__main__": main() 

Otherwise you can have it called however you want, as long it the function is executed at runtime, which it currently isn't.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.