fork download
  1. # at the top:
  2. import operator
  3.  
  4. # the rest of your application
  5.  
  6. operator = input("Enter your oeprator out of: ...")
  7. if operator not in ("+", ...):
  8. raise ValueError(f"Invalid Operator: {operator}")
  9.  
  10. def mydivision(num1: float, num2: float) -> float:
  11. if num2 == 0:
  12. raise ValueError("Division by zero not allowed")
  13. return num1 / num2
  14.  
  15. OPERATOR_MAP = {
  16. "+": operator.add,
  17. "*": operator.mul,
  18. "-": operator.sub,
  19. "/": mydivision, # because of null handling
  20. }
  21.  
  22. MESSAGE_MAP = {
  23. "+": "The sum of two numbers is: ",
  24. "*": "The multiplication of two numbers is: ",
  25. "-": "The subtraction of two numbers is: ",
  26. "/": "The division of two numbers is: ",
  27. }
  28.  
  29. result = OPERATOR_MAP[operator](num1, num2)
  30. print(MESSAGE_MAP[operator], result)
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/py_compile.py", line 117, in compile
    raise py_exc
py_compile.PyCompileError:   File "prog.py", line 7
    if operator not in ("+", ...):
                             ^
SyntaxError: invalid syntax

stdout
Standard output is empty