desislava_topuzakova

07. Operations Between Numbers

May 3rd, 2020
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. n1 = int(input())
  2. n2 = int(input())
  3. operator = input()
  4.  
  5. # + - * / %
  6.  
  7. if operator == '+':
  8.     # събиране
  9.     sum = n1 + n2
  10.     if sum % 2 == 0:
  11.         print(f'{n1} + {n2} = {sum} - even')
  12.     else:
  13.         print(f'{n1} + {n2} = {sum} - odd')
  14. elif operator == '-':
  15.     # изваждане
  16.     diff = n1 - n2
  17.     if diff % 2 == 0:
  18.         print(f'{n1} - {n2} = {diff} - even')
  19.     else:
  20.         print(f'{n1} - {n2} = {diff} - odd')
  21. elif operator == '*':
  22.     # умножение
  23.     result = n1 * n2
  24.     if result % 2 == 0:
  25.         print(f'{n1} * {n2} = {result} - even')
  26.     else:
  27.         print(f'{n1} * {n2} = {result} - odd')
  28. elif operator == '/':
  29.     # деление
  30.     # проверка дали можем да делим
  31.     if n2 == 0:
  32.         print(f'Cannot divide {n1} by zero')
  33.     else:
  34.         division = n1 / n2
  35.         print(f'{n1} / {n2} = {division:.2f}')
  36. elif operator == '%':
  37.     # деление с остатък
  38.     # проверка дали можем да делим
  39.     if n2 == 0:
  40.         print(f'Cannot divide {n1} by zero')
  41.     else:
  42.         leftover = n1 % n2
  43.         print(f'{n1} % {n2} = {leftover}')
Advertisement
Add Comment
Please, Sign In to add comment