Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 941f63d

Browse files
updated calc program
Signed-off-by: Mukesh Sai Madepalli <madepallimukesh@gmail.com>
1 parent bcc4378 commit 941f63d

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

‎Calculator/Calcy.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,24 @@
1313
previous = 0
1414
run = True
1515

16-
1716
def performMath():
1817
global run
1918
global previous
20-
equation = ""
21-
if previous == 0:
22-
equation = input("Enter Equation:")
23-
else:
24-
equation = input(str(previous))
19+
equation = input("Enter Equation: ")
2520

2621
if equation == 'quit':
27-
print("GoodBye, Human..!")
22+
print("Goodbye, Human..!")
2823
run = False
29-
3024
else:
3125
equation = re.sub('[a-zA-Z,:()"{}"]', '', equation)
3226

33-
if previous == 0:
34-
previous = eval(equation)
35-
else:
36-
previous = eval(str(equation) + equation)
37-
27+
try:
28+
if previous == 0:
29+
previous = eval(equation)
30+
else:
31+
previous = eval(str(previous) + equation)
32+
except Exception as e:
33+
print("Invalid equation. Please try again.")
3834

3935
while run:
4036
performMath()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /