Advertisement
veronikaaa86

06. Operations Between Numbers

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