Advertisement
simeonshopov

Operations

Sep 25th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. n1 = int(input())
  2. n2 = int(input())
  3. operator = input()
  4.  
  5. result = 0
  6. output = ""
  7.  
  8. if n2 == 0:
  9.   if operator == '/' or  operator == '%':
  10.     output = f"Cannot divide {n1} by zero"
  11. elif operator == "/":
  12.   result = n1 / n2
  13.   output = f"{n1} {operator} {n2} = {result:.2f}"
  14. elif operator == "%":
  15.   result = n1 % n2
  16.   output = f"{n1} {operator} {n2} = {result}"
  17. else:
  18.   if operator == "+":
  19.     result = n1 + n2
  20.   elif operator == "-":
  21.     result = n1 - n2
  22.   elif operator == "*":
  23.     result = n1 * n2
  24.   output = f"{n1} {operator} {n2} = {result} "\
  25.   f"- {'even' if result % 2 == 0 else 'odd'}"
  26.  
  27. print(output)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement