Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n1 = int(input())
- n2 = int(input())
- operator = input()
- # + - * / %
- if operator == '+':
- # събиране
- sum = n1 + n2
- if sum % 2 == 0:
- print(f'{n1} + {n2} = {sum} - even')
- else:
- print(f'{n1} + {n2} = {sum} - odd')
- elif operator == '-':
- # изваждане
- diff = n1 - n2
- if diff % 2 == 0:
- print(f'{n1} - {n2} = {diff} - even')
- else:
- print(f'{n1} - {n2} = {diff} - odd')
- elif operator == '*':
- # умножение
- result = n1 * n2
- if result % 2 == 0:
- print(f'{n1} * {n2} = {result} - even')
- else:
- print(f'{n1} * {n2} = {result} - odd')
- elif operator == '/':
- # деление
- # проверка дали можем да делим
- if n2 == 0:
- print(f'Cannot divide {n1} by zero')
- else:
- division = n1 / n2
- print(f'{n1} / {n2} = {division:.2f}')
- elif operator == '%':
- # деление с остатък
- # проверка дали можем да делим
- if n2 == 0:
- print(f'Cannot divide {n1} by zero')
- else:
- leftover = n1 % n2
- print(f'{n1} % {n2} = {leftover}')
Advertisement
Add Comment
Please, Sign In to add comment