Create a gist now

Instantly share code, notes, and snippets.

@wkta /day_10.py
Last active Aug 29, 2015

What would you like to do?
#MonthOfCode day 10 - switch
# 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