Loading...
Loading...
Loading...
In postfix notation, an operator comes after its two numbers, so 3 4 + means 3 plus 4. Evaluate a postfix expression with + - * and /. Division gives an integer that truncates toward zero, so -7 divided by 2 is -3. The divisor is never zero.
Example 1
Input
3 4 + 2 *
Output
14
(3 + 4) * 2 = 14.
Example 2
Input
10 3 /
Output
3
Try the problem first. Open one hint at a time.
Push numbers. When you see an operator, pop two values.
The first pop is the right operand. Truncate division with int(a / b).
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor