IntermediateChallenge 25 of 34

Expression calculator

Write evaluate(expr) that computes an arithmetic expression given as a , supporting + - * /, parentheses, decimal numbers and the usual precedence. Do not use eval().

Examples
evaluate("2 + 3 * 4") → 14
evaluate("(2 + 3) * 4") → 20
evaluate("10 / 4") → 2.5
Exercise

Expression calculator

5 checks
def evaluate(expr):
    ...


print(evaluate("2 + 3 * 4"), evaluate("(2 + 3) * 4"))
 
Python (loads on first run)Ctrl+Enter runs
Output
Press Run to try your code, then Check answer to grade it.