dkyoseff

Conditional Statements Advanced - Exercise / 06. Operations Between Numbers

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