Reverse Polish Notation Evaluator (Python vs Truncated Division)
Difficulty: Medium · Unit 4: Files, Exceptions & Standard Library · Featured in: CodeTantra Lab Pattern
Evaluate a Reverse Polish Notation (postfix) expression containing integers and operators `+`, `-`, `*`, `/` where integer division `/` must truncate toward zero (so `-7 / 2 == -3`, NOT Python's floor `-4`). Return `ERR_ZERO` if division by zero occurs or `ERR_SYNTAX` if the token stream is invalid.
Input & Output Format
Input: A single line of space-separated RPN tokens.
Output: Print the integer result, or `ERR_ZERO` / `ERR_SYNTAX`.
Sample 1
10 6 9 3 + -11 * / * 17 + 5 +
22
6 / -132 truncates toward zero to 0 -> 10 * 0 + 17 + 5 = 22.
Free forever — sign in with email at poorvithmp.com to unlock the dry run, verified Python 3 solution, edge-case traps, and downloads.