Sichanov

operations between numbers

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