Skip to content

Commit 139aae6

Browse files
semalPatelkeon
authored andcommitted
fix calculator infinite loop (keon#466)
1 parent 141bcc6 commit 139aae6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

algorithms/calculator/math_parser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def parse(expression):
9393
result.append(i)
9494
else:
9595
raise Exception("invalid syntax " + i)
96-
96+
9797
if len(current) > 0:
9898
result.append(current)
9999
return result
@@ -133,15 +133,17 @@ def main():
133133
simple user-interface
134134
"""
135135
print("\t\tCalculator\n\n")
136-
user_input = input("expression or exit: ")
137-
while user_input != "exit":
136+
while True:
137+
user_input = input("expression or exit: ")
138+
if user_input == "exit":
139+
break
138140
try:
139141
print("The result is {0}".format(evaluate(user_input)))
140142
except Exception:
141143
print("invalid syntax!")
142144
user_input = input("expression or exit: ")
143145
print("program end")
144-
146+
145147

146148
if __name__ == "__main__":
147149
main()

0 commit comments

Comments
 (0)