BbJLeB

07. Operations Between Numbers

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