Skip to content

Commit 08d725c

Browse files
calculator
1 parent 47315ca commit 08d725c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Calculator/Calcy.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Mon Jul 6 23:26:25 2020
4+
5+
@author: Avinash Ranjan
6+
"""
7+
8+
import re
9+
10+
print("Magical Calculator")
11+
print("Type 'quit' to exit\n")
12+
13+
previous = 0
14+
run = True
15+
16+
def performMath():
17+
global run
18+
global previous
19+
equation = ""
20+
if previous == 0:
21+
equation = input("Enter Equation:")
22+
else:
23+
equation = input(str(previous))
24+
25+
if equation == 'quit':
26+
print("GoodBye, Human..!")
27+
run = False
28+
29+
else:
30+
equation = re.sub('[a-zA-Z,:()"{}"]', '', equation)
31+
32+
if previous == 0:
33+
previous = eval(equation)
34+
else:
35+
previous = eval(str(equation) + equation)
36+
37+
while run:
38+
performMath()

0 commit comments

Comments
 (0)