Expression evaluator

Implement expression evaluator (similar to your calculator) using Python. The input text files t5.dat should be at the same directory with your p5.py or p5.ipynb file. Each input file has only one expression consists of positive integers, whitespaces like space (‘ ‘) or tab, add (‘+’), multiply (‘’), open parenthesis (‘(‘), and close parenthesis (‘)’). If input contains any other characters or imbalanced open and close parenthesis, your p5 should report error and handle the next input file if there is one. The parenthesis has the highest precedence, the * is second highest, and + is the lowest. Since you read input as a character string, you need to convert numbers to integer by int(). If the input is a legal expression, your b5 should output correct answer for the expression.

Example input and output:
t50.dat:
2(5+33)
The output for t50.dat should be 28
t51.dat:
(1 + 2 * (51 + 3 * 3)) * 12 + 110
The output for t51 should be 1562
t59.dat:
(1+a)) + 1 * ((2)

This question has been answered.

Get Answer