Advertisement
veronikaaa86

06. Operations Between Numbers

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