Advertisement
Guest User

Untitled

a guest
Oct 30th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. def one():
  2.     print("This is the first function")
  3.  
  4. def two():
  5.     print("This is the second function")
  6.  
  7. def three():
  8.     print("This is the third function")
  9.  
  10. def main():
  11.     functions = [
  12.         {
  13.             'keywords': ('o', 'one', 'bob'),
  14.             'function': one
  15.         },
  16.         {
  17.             'keywords': ('t', 'two'),
  18.             'function': two
  19.         },
  20.         {
  21.             'keywords': ('th', 'three'),
  22.             'function': three
  23.         }
  24.     ]
  25.     while True:
  26.         print("\nWhich function would you like to run?")
  27.         choice = input(', '.join( [x['function'].__name__ for x in functions] ) + ', [q]uit: ' )
  28.         for entry in functions:
  29.             if choice in entry['keywords']:
  30.                 entry['function']()
  31.                 break #found a function, go back to the outer loop
  32.         else: # this executes when there wasn't a break
  33.             if choice in ['q', 'quit']:
  34.                 print("Bye")
  35.                 break #exit the main loop
  36.             else:
  37.                 print("Sorry, I couldn't find that function")
  38.                 continue #back to top
  39.  
  40.  
  41. if __name__ == "__main__":
  42.         main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement