#MonthOfCode day 10 - switch
This file contains 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
# As you know there's no such thing as a switch statement in python | |
# but it can be easily simulated using functions | |
def switch_simu( val, funct_dict): | |
if( not val in funct_dict.keys()): | |
funct_dict[ 'default']() | |
return | |
funct_dict[ val]() | |
def below2Message(): | |
print 'you type an integer below 2' | |
def below4Message(): | |
print 'you type an integer between 2 and 4 (inclusive)' | |
def do_some_fancy_stuff(): | |
print 'you typed 5 or more' | |
print 'please type a positive integer' | |
num = int( raw_input() ) | |
switch_simu( num, { | |
0: below2Message, | |
1: below2Message, | |
2: below4Message, | |
3: below4Message, | |
4: below4Message, | |
'default': do_some_fancy_stuff | |
} ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment