Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # fn_switchcase.py
- # define the function blocks
- def zero():
- return "Integer zero also registers as a False statement by default.\n"
- def one():
- return "The integer one was entered.\n"
- def two():
- return "5 minus 3 equals 2.\n"
- def a_float():
- return "The decimal 0.5 is a float in Python.\n"
- def sA():
- return "The letter 'z' is a string in Python.\n"
- def sB():
- return "Nice to meet you.\n"
- def sC():
- return "Even accepting of tuples... Python dictionaries are awesome!\n"
- # map the inputs to the function blocks
- options = {0 : zero,
- 'z' : sA,
- 1 : one,
- 2 : two,
- 0.5 : a_float,
- 'Hi' : sB,
- (0,255,0) : sC
- }
- a = 5
- b = 3
- for z in [0,1,'NO!',a-b,0.5,'Hi',(0,255,0),'z']:
- if z in options:
- print(options[z]())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement