Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. # take in 2 numbers and an operator
  2. num1, op, num2 = input('enter 2 numbers and an operator ').split()
  3.  
  4. # convert str to int
  5. num1 = int(num1)
  6. num2 = int(num2)
  7.  
  8. # if (which ever op) {do the math}
  9. if op.lower() == '+':
  10. sum = num1 + num2
  11. print(f'{num1} + {num2} = {sum}')
  12.  
  13. if op.lower() == '-':
  14. difference = num1 - num2
  15. print(f'{num1} - {num2} = {difference}')
  16.  
  17. if op.lower() == '*':
  18. times = num1 * num2
  19. print(f'{num1} * {num2} = {times}')
  20.  
  21. if op.lower() == '/':
  22. divide = num1 / num2
  23. print(f'{num1} / {num2} = {divide}')
  24.  
  25. if op.lower() == '%':
  26. remainder = num1 % num2
  27. print(f'{num1} % {num2} = {remainder}')
  28. else:
  29. print('use either + - * / or % next time')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement