-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathccalc.py
executable file
·44 lines (37 loc) · 1.06 KB
/
ccalc.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
#!/usr/bin/env python3
__author__ = "Jugal Kishore"
__version__ = "1.1"
import re
def find_sign():
global equation
var = 0
signs = ["+", "-", "*", "/", "%"]
number_of_signs = len(signs)
for value in signs:
if equation[0].find(value) == -1:
var += 1
return var != number_of_signs
previous = 0
run = True
print("///Advanced Calculator///\n")
print("Type 'quit' to exit\n")
while run:
if previous == 0:
equation = input("Enter equation:\n")
else:
equation = input(str(previous))
if equation == "quit":
print("Uh-Oh, you decided to exit.")
print("Exiting!")
break
else:
equation = re.sub('[a-zA-Z,.:()" "]', "", equation)
if previous == 0:
previous = eval(equation)
else:
if find_sign() is True:
previous = eval(str(previous) + equation)
else:
print("Check the mathematical signs, Try Again!")
print("\nCreated by Jugal Kishore -- 2020")
# Run it online at https://python.jugalkishore.repl.run/