Advertisement
here2share

# fn_switchcase.py

May 5th, 2020
1,299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. # fn_switchcase.py
  2.  
  3. # define the function blocks
  4. def zero():
  5.     return "Integer zero also registers as a False statement by default.\n"
  6.  
  7. def one():
  8.     return "The integer one was entered.\n"
  9.  
  10. def two():
  11.     return "5 minus 3 equals 2.\n"
  12.  
  13. def a_float():
  14.     return "The decimal 0.5 is a float in Python.\n"
  15.  
  16. def sA():
  17.     return "The letter 'z' is a string in Python.\n"
  18.  
  19. def sB():
  20.     return "Nice to meet you.\n"
  21.  
  22. def sC():
  23.     return "Even accepting of tuples... Python dictionaries are awesome!\n"
  24.  
  25. # map the inputs to the function blocks
  26. options = {0            : zero,
  27.            'z'          : sA,
  28.            1            : one,
  29.            2            : two,
  30.            0.5          : a_float,
  31.            'Hi'         : sB,
  32.            (0,255,0)    : sC
  33. }
  34.  
  35. a = 5
  36. b = 3
  37.  
  38. for z in [0,1,'NO!',a-b,0.5,'Hi',(0,255,0),'z']:
  39.     if z in options:
  40.         print(options[z]())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement