Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 30th, 2013  |  syntax: Python  |  size: 1.16 KB  |  views: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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()
clone this paste RAW Paste Data