Advertisement
GeorgiLukanov87

operation betweennumbers 100/100

Mar 14th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. Operation between numbers
  2. =================================================================
  3.  
  4. n1 = int(input())
  5. n2 = int(input())
  6. operator = input()
  7.  
  8. result = 0
  9. status1 = "even"
  10. status2 = 'odd'
  11.  
  12. if operator == "+":
  13.     result = n1 + n2
  14.     if result % 2 == 0:
  15.         print(f"{n1} {operator} {n2} = {result} - {status1}")
  16.     else:
  17.         print(f"{n1} {operator} {n2} = {result} - {status2}")
  18.  
  19. elif operator == "-":
  20.     result = n1 - n2
  21.     if result % 2 == 0:
  22.         print(f"{n1} {operator} {n2} = {result} - {status1}")
  23.     else:
  24.         print(f"{n1} {operator} {n2} = {result} - {status2}")
  25.  
  26. elif operator == "*":
  27.     result = n1 * n2
  28.     if result % 2 == 0:
  29.         print(f"{n1} {operator} {n2} = {result} - {status1}")
  30.     else:
  31.         print(f"{n1} {operator} {n2} = {result} - {status2}")
  32.  
  33. elif operator == '/':
  34.     if n2 != 0:
  35.         result = n1 / n2
  36.         print(f"{n1} / {n2} = {result:.2f}")
  37.     else:
  38.         print(f'Cannot divide {n1} by zero')
  39.  
  40. elif operator == '%':
  41.     if n2 != 0:
  42.         result = n1 % n2
  43.         print(f"{n1} % {n2} = {result}")
  44.     else:
  45.         print(f'Cannot divide {n1} by zero')
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement