-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
54 lines (40 loc) · 1.61 KB
/
calculator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""CLI application for a prefix-notation calculator."""
from arithmetic import (add, subtract, multiply, divide, square, cube,
power, mod)
def calculator():
problem = ""
while problem != "q":
problem = input("Enter your equation > ")
problemsplit = problem.split(' ')
operator = problemsplit[0]
if operator == "add" or operator == "+":
num1 = float(problemsplit[1])
num2 = float(problemsplit[2])
print(add(num1, num2))
elif operator == "subtract" or operator == "-":
num1 = float(problemsplit[1])
num2 = float(problemsplit[2])
print(subtract(num1, num2))
elif operator == "power" or operator == "**":
num1 = float(problemsplit[1])
num2 = float(problemsplit[2])
print(power(num1, num2))
elif operator == "multiply" or operator == "*":
num1 = float(problemsplit[1])
num2 = float(problemsplit[2])
print(multiply(num1, num2))
elif operator == "%" or operator == "mod":
num1 = float(problemsplit[1])
num2 = float(problemsplit[2])
print(mod(num1, num2))
elif operator == "divide" or operator == "/":
num1 = float(problemsplit[1])
num2 = float(problemsplit[2])
print(divide(num1, num2))
elif operator == "square":
num1 = float(problemsplit[1])
print(square(num1))
elif operator == "cube":
num1 = float(problemsplit[1])
print(cube(num1))
calculator()