← Back to challenges

Solve the Equation

PythonMediummathlanguage_fundamentals

Instructions

Create a function that takes an equation (e.g. "1+1"), and returns the answer.

Examples

equation("1+1") ➞ 2

equation("7*4-2") ➞ 26

equation("1+1+1+1+1") ➞ 5

Notes

Supported operators are +, -, and *.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Triangle and Parallelogram Area Finder