← Back to challenges

Prefix Notation Evaluation

PythonHarddata_structuresarrayslanguage_fundamentals

Instructions

Create a function that takes a mathematical expression in prefix notation as a string and evaluates the expression.

Examples

prefix("+ 5 4") ➞  9

prefix("* 12 2") ➞  24

prefix("+ -10 10") ➞  0

Notes

  • The mathematical expression is valid.
  • Use // for division.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.