-
-
Save 1328/16e8e074bf3abfd7a7d6 to your computer and use it in GitHub Desktop.
menus
This file contains hidden or 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
| def get_input(valid): | |
| while True: | |
| choice = input('->') | |
| if choice not in valid: | |
| print('not a valid option') | |
| else: | |
| return choice | |
| def menu_one(): | |
| print (""" | |
| ---------------------- | |
| This is Menu 1. | |
| 1. Submenu 1 again | |
| 2. Submenu 2 | |
| Return to the main menu by typing '0' | |
| ---------------------- | |
| """) | |
| choice = get_input(['0','1','2']) | |
| if choice == '0': | |
| return main_menu | |
| elif choice == '1': | |
| return menu_one | |
| elif choice == '2': | |
| return menu_two | |
| else: | |
| print('not implemented yet') | |
| def menu_two(): | |
| print (""" | |
| ---------------------- | |
| This is Menu 2. | |
| 1. Submenu 1 | |
| 2. Submenu 3 | |
| Return to the main menu by typing '0' | |
| ---------------------- | |
| """) | |
| choice = get_input(['0','1','2']) | |
| if choice == '0': | |
| return main_menu | |
| elif choice == '1': | |
| return menu_one | |
| else: | |
| print('not implemented yet') | |
| return menu_two | |
| def main_menu(): | |
| print (""" | |
| ---------------------- | |
| This is the main menu: | |
| 1. Submenu 1 | |
| 2. Submenu 2 | |
| 3. Submenu 2 | |
| quit by typing '0' | |
| ---------------------- | |
| """) | |
| choice = get_input(['0','1','2','3']) | |
| if choice == '0': | |
| return | |
| elif choice == '1': | |
| return menu_one | |
| elif choice == '2': | |
| return menu_two | |
| else: | |
| print('not implemented yet') | |
| return main_menu | |
| def main(): | |
| current = main_menu | |
| while True: | |
| current = current() | |
| if current is None: | |
| return | |
| if __name__ == '__main__': | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment