Question: Python Use this template Implement a Reverse Polish Notation calculator by adding code to the given template file. Test your program by calculating the given
Python
Use this template
Implement a Reverse Polish Notation calculator by adding code to the given template file. Test your program by calculating the given RPN expression hard-coded in the template. Do not use Lambda functions.
Main focus on stack.
Result should look like this:
The Reverse Polish Notation is "19 2.14 + 4.5 2 4.3 / - &"
The result is 85.29744186046511
def evalTokens (tokens): # Evaluate RPN expression in 'tokens' stack # Put your code here (note: you will get error "pop from emply list" # if you just run the template without putting something in stack) return stack.pop 0 rp3 1" rpn- "19 2.14 + 4.5 2 4.3 / - *" # Infix: (19 + 2.14) * (4.5-2 / 4.3); answer-85.29 # Test this first; make sure your answer is 2 and not-2 rpn_tokens.split("" resultstr (evalTokens (rpn_tokens)) print( 'The Reverse Polish Noation is " ' + rpn + '''') print( 'The result is ' + result) # should be 85.29744186046511 for above test line
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
