Advertisement
Spocoman

06. Operations Between Numbers

Dec 21st, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. first_num = int(input())
  2. second_num = int(input())
  3. operator = input()
  4. result = 0.0
  5.  
  6. if operator == '+' or operator == '-' or operator == '*':
  7.     if operator == '+':
  8.         result = first_num + second_num
  9.     elif operator == '-':
  10.         result = first_num - second_num
  11.     else:
  12.         result = first_num * second_num
  13.  
  14.     even_ood = 'even' if result % 2 == 0 else 'odd'
  15.     print(f'{first_num} {operator} {second_num} = {result} - {even_ood}')
  16.  
  17. else:
  18.     print(f'Cannot divide {first_num} by zero' if second_num == 0 else
  19.           f'{first_num} {operator} {second_num} = {first_num % second_num}' if operator == "%"
  20.           else f'{first_num} {operator} {second_num} = {first_num / second_num:.2f}')
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement