Question: rpn.py: Write an interpreter for a reverse Polish notation (RPN) calcu- lator. Each line of the input corresponds to a single operand or operator. Operands

 rpn.py: Write an interpreter for a reverse Polish notation (RPN) calcu-

rpn.py: Write an interpreter for a reverse Polish notation (RPN) calcu- lator. Each line of the input corresponds to a single operand or operator. Operands should be pushed onto a stack, and popped as needed when an operator is encountered (and the result pushed back on the stack) At each step, you should print the top-most element on the stack. If an operator requires more elements than are available on the stack, you should print "invalid operation" and ignore the operator. Operands will be non-negative integers. You should support these operators: + Add two numbers Subtract two numbers * Multiply two numbers / Divide two numbers Negate one number Example: 23 # prints 23 # prints 5 # pops 23 and 5, pushes and prints 28 Another example: # prints 1 # prints 2 # pops 1 # prints 5 # prints 1 # pops 5 # pops 3 2 and 2, pushes and prints 3 5 4 and 1, pushes and prints and 4, pushes and prints 7

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!