-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basic_Calculator.py
43 lines (30 loc) · 915 Bytes
/
Basic_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
import re
print('Basic Calculator')
print("Type 'quit' to exit")
print("Type 'reopen' to start with 0\n")
print("Type 'help' if you need")
previous = 0
run = True
def perform_math():
global run
global previous
equation = ''
if previous == 0:
equation = input('Enter equation: ')
else:
equation = input(str(previous) + ' ')
if equation == 'quit':
run = False
print('Goodbye Human!')
elif equation == "help":
print('This terminal calculator is degined for generel purpose')
elif equation == 'reopen':
previous = 0
else:
equation = re.sub('[a-zA-Z,:.()@#!$^&_=;\'|><" "]', '', equation)
if previous == 0:
previous = eval(equation)
else:
previous = eval(str(previous) + equation)
while run:
perform_math()