Advertisement
veronikaaa86

06. Operations Between Numbers

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