Ciemny_Cygan

python3_switch_example

Dec 1st, 2020
658
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class switch():
  2.     value = None
  3.     def __new__(class_, value):
  4.         class_.value = value
  5.         return True
  6.  
  7. def case(*args):
  8.     return any((arg == switch.value for arg in args))
  9.  
  10.  
  11. n = int(input())
  12.  
  13. while switch(n):
  14.     if case(0):
  15.         print("You typed zero.")
  16.         break
  17.     if case(1, 4, 9):
  18.         print("n is a perfect square.")
  19.         break
  20.     if case(2):
  21.         print("n is an even number.")
  22.     if case(2, 3, 5, 7):
  23.         print("n is a prime number.")
  24.         break
  25.     if case(6, 8):
  26.         print("n is an even number.")
  27.         break
  28.     print("Only single-digit numbers are allowed.")
  29.     break
RAW Paste Data