Reputation: 131
I'm trying to create a function in python that outputs a menu like this:
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?
Upvotes: 0
Views: 84
Reputation: 6360
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.
Upvotes: 0
Reputation: 1165
you probably need parentheses around your text..
def display_menu():
print ("###MENU###")
print ("p) Play the matching penny game")
print ("q) Quit")
display_menu()
Upvotes: 0
Reputation: 59
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()
Upvotes: 1
Reputation: 3349
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.
Upvotes: 0