Skip to content

Instantly share code, notes, and snippets.

@KyeRussell
Created July 20, 2011 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KyeRussell/1094778 to your computer and use it in GitHub Desktop.
Save KyeRussell/1094778 to your computer and use it in GitHub Desktop.
IfElse alternative
derp = raw_input()
if derp == 'a':
pass
elif derp == 'b':
pass
elif derp == 'c':
pass
else:
print "Invalid Choice"
# ^^^epic grossness^^^
# Function definitions
def a_function():
"""Function for choice a"""
pass
def b_function():
"""Function for choice b"""
pass
def c_function():
"""Function for choice c"""
pass
# Map choices to functions.
choices = {'a': a_function,
'b': b_function,
'c': c_function}
# Poll for selection.
print "Select something... ",
user_selection = raw_input()
# Cycle through choices.
for choice in choices.keys():
# Check if the current selection is what the user wants.
if choice = user_selection:
# Execute the associated function.
choices[choice]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment