Skip to content

Instantly share code, notes, and snippets.

@impshum
Last active March 14, 2020 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save impshum/bc91de030c133a9fbcf2052362ae9a39 to your computer and use it in GitHub Desktop.
Save impshum/bc91de030c133a9fbcf2052362ae9a39 to your computer and use it in GitHub Desktop.
Return user input from dictionary
things = {
'1': 'one',
'2': 'two',
'3': 'three',
'0': 'EXIT'
}
def menu(options, menu_text):
while 1:
for k, v in options.items():
print(k, v)
user_choice = options.get(input(menu_text))
if user_choice:
return user_choice
choice = menu(things, 'Choose a thing: ')
print(choice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment