Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def one():
- print("This is the first function")
- def two():
- print("This is the second function")
- def three():
- print("This is the third function")
- def main():
- functions = [
- {
- 'keywords': ('o', 'one', 'bob'),
- 'function': one
- },
- {
- 'keywords': ('t', 'two'),
- 'function': two
- },
- {
- 'keywords': ('th', 'three'),
- 'function': three
- }
- ]
- while True:
- print("\nWhich function would you like to run?")
- choice = input(', '.join( [x['function'].__name__ for x in functions] ) + ', [q]uit: ' )
- for entry in functions:
- if choice in entry['keywords']:
- entry['function']()
- break #found a function, go back to the outer loop
- else: # this executes when there wasn't a break
- if choice in ['q', 'quit']:
- print("Bye")
- break #exit the main loop
- else:
- print("Sorry, I couldn't find that function")
- continue #back to top
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement