Advertisement
gruntfutuk

simple menu

Jul 9th, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. # simple menu
  2. MENU_CHOICES = "1234x"
  3.  
  4. while True:  # menu loop
  5.     while True:  # validation loop
  6.         choice = input('Enter choice 1-4 (or x to exit): ').lower()
  7.         if choice and choice in MENU_CHOICES:
  8.             break  # break out of validation loop
  9.         print('Not a valid choice, try again.')
  10.     if choice == 'x':  # break out of menu loop
  11.         break
  12.     if choice == "1":
  13.         print('doing menu 1 stuff')
  14.     elif choice == "2":
  15.         print('doing menu 2 stuff')
  16.     elif choice == "3":
  17.         print('doing menu 3 stuff')
  18.     else:  # must be 4
  19.         print('doing menu 4 stuff')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement