Postfix Calculator With A Stack
Postfix Calculator With A Stack
The Stack class is given. Write evaluate_postfix(tokens: list[str]) -> int that evaluates an expression written in postfix notation, where each operator follows its two operands, so 3 4 + 2 * means (3 + 4) * 2. Walk the tokens: a number (test it with isdigit()) is converted with int() and pushed; an operator +, - or * pops the right operand first and the left operand second, applies the operation and pushes the result. The expression is always valid and only uses non-negative whole numbers; the answer is whatever is left on the stack at the end. Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one line of space-separated tokens, which the tests split and pass to your function before printing the value it returns.
Expected Output:
14= newline. The output ends with a newline — print one after the last line.
Your Output
Run your code to see the output here...