-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
53 lines (39 loc) · 1.34 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
52
53
"""
Created by Neel Gokhale at 2020-07-19
File calculator.py from project Project_Calculator
Built using PyCharm
"""
import functions as f
run = True
print("___Python Calculator___")
while run:
num1 = float(input("> Please enter the first number: "))
num2 = float(input("> Please enter the second number: "))
print(
"""
The following arithmetic operators can be used:
- For addition, press A
- For subtraction, press S
- For multiplications, press M
- For division, press D
- For power function, press P
- To quit, press X
"""
)
op = input("> Enter operator key: ").lower()
if op == 'x':
break
elif op == 'a':
print("> The answer is: ", f.add(num1, num2))
elif op == 's':
in_order = bool(int(input(">> Enter 1 -> num1 - num2 OR Enter 0 -> num2 - num1: ")))
print("> The answer is: ", f.subtract(num1, num2, in_order=in_order))
elif op == 'm':
print("> The answer is: ", f.multiply(num1, num2))
elif op == 'd':
in_order = bool(int(input(">> Enter 1 -> num1 / num2 OR Enter 0 -> num2 / num1")))
print("> The answer is: ", f.divide(num1, num2, in_order=in_order))
elif op == 'p':
print("> The answer is: ", f.power(num1, num2))
else:
print("> Invalid entry, try again...")