0

Hello i'm rather new to Python and I was wondering how I could do a menu to prompt the user to choose a number and execute a certain part of code based on his choice.

For example:

please choose an option
1)
2)
3)

then based on users input, it executes only that part of the code.

Would i just do something like

if choice ==1 :
do this

if choice ==2:
do this

ect?

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Gribouillis
0

Would i just do something like

if choice ==1 :
do this

if choice ==2:
do this

ect?

Yeah pretty much. That's the most straight forward way to approach this problem

usr_inp = raw_input( 'Enter your choice (1-3): ' )

if usr_inp == '1':
    # do something for 1
elif usr_inp == '2':
    # do another thing for 2
elif usr_inp == '3':
    # do the number 3 thing
else:
    print 'Invalid Option'
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.