Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- Simple calculator in Python
- Coded by Donny
- '''
- def ans(x):
- print("The answer is : ",x,"\n")
- def add(x, y):
- sum = x + y
- ans(sum)
- def sub(x, y):
- min = x - y
- ans(min)
- def div(x, y):
- divis = x / y
- ans(divis)
- def mul(x, y):
- mult = x * y
- ans(mult)
- usrin = input(">>> ")
- divide = usrin.split(' ')
- first = divide[0]
- op = divide[1]
- second = divide[2]
- if not first:
- print("The first number should not be left blank!")
- exit
- elif not second:
- print("The second number should not be left blank!")
- exit
- elif not op:
- print("The operator should not be left blank!")
- first = int(first)
- second = int(second)
- if op == '+':
- add(first, second)
- elif op == '-':
- sub(first, second)
- elif op == '/':
- div(first, second)
- elif op == '*':
- mul(first, second)
- else:
- print("ERROR! Invalid OP!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement