Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # take in 2 numbers and an operator
- num1, op, num2 = input('enter 2 numbers and an operator ').split()
- # convert str to int
- num1 = int(num1)
- num2 = int(num2)
- # if (which ever op) {do the math}
- if op.lower() == '+':
- sum = num1 + num2
- print(f'{num1} + {num2} = {sum}')
- if op.lower() == '-':
- difference = num1 - num2
- print(f'{num1} - {num2} = {difference}')
- if op.lower() == '*':
- times = num1 * num2
- print(f'{num1} * {num2} = {times}')
- if op.lower() == '/':
- divide = num1 / num2
- print(f'{num1} / {num2} = {divide}')
- if op.lower() == '%':
- remainder = num1 % num2
- print(f'{num1} % {num2} = {remainder}')
- else:
- print('use either + - * / or % next time')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement