fork download
  1. from math import factorial
  2.  
  3.  
  4. def fact(a):
  5. return factorial(a)
  6.  
  7.  
  8. def root(a):
  9. return a ** (1/2)
  10.  
  11.  
  12. def square(a):
  13. return a ** 2
  14.  
  15.  
  16. def cube(a):
  17. return a ** 3
  18.  
  19.  
  20. commands = [
  21. {'match':'root', 'func': root },
  22. {'match':'!', 'func': fact },
  23. {'match':'²', 'func': square },
  24. {'match':'³', 'func': cube },
  25. ]
  26.  
  27. input_command = input()
  28.  
  29. for command in commands:
  30. if command["match"] in input_command:
  31. val = int(input_command.strip(command["match"]))
  32. print(command["func"](val))
  33. break
  34.  
Success #stdin #stdout 0.04s 9564KB
stdin
5!
stdout
120