Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 13:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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']()
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