Created
July 20, 2011 11:15
-
-
Save KyeRussell/1094778 to your computer and use it in GitHub Desktop.
IfElse alternative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
derp = raw_input() | |
if derp == 'a': | |
pass | |
elif derp == 'b': | |
pass | |
elif derp == 'c': | |
pass | |
else: | |
print "Invalid Choice" | |
# ^^^epic grossness^^^ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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