Last active
March 14, 2020 13:09
-
-
Save impshum/bc91de030c133a9fbcf2052362ae9a39 to your computer and use it in GitHub Desktop.
Return user input from dictionary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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