Advertisement
Lyubohd

06. Operations Between Numbers

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