Skip to content

Commit

Permalink
fix calculator infinite loop (keon#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
semalPatel authored and keon committed Dec 20, 2018
1 parent 141bcc6 commit 139aae6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions algorithms/calculator/math_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def parse(expression):
result.append(i)
else:
raise Exception("invalid syntax " + i)

if len(current) > 0:
result.append(current)
return result
Expand Down Expand Up @@ -133,15 +133,17 @@ def main():
simple user-interface
"""
print("\t\tCalculator\n\n")
user_input = input("expression or exit: ")
while user_input != "exit":
while True:
user_input = input("expression or exit: ")
if user_input == "exit":
break
try:
print("The result is {0}".format(evaluate(user_input)))
except Exception:
print("invalid syntax!")
user_input = input("expression or exit: ")
print("program end")


if __name__ == "__main__":
main()

0 comments on commit 139aae6

Please sign in to comment.