Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use Python to create a simple calculator that accepts Reverse Polish Notation ( RPN ) and displays the final answer ( Intermediate steps or results
Use Python to create a simple calculator that accepts Reverse Polish Notation RPN and displays the final answer Intermediate steps or results need not be displayed
It only accepts operators
Input numbers will be single digits.
The input will be in postfix notation.
The input will be provided in a text file called inputRPNtxt
Your program should not ask the user for any input.
There will be one RPN expression in each line.
Each digit and symbol will be space delimited.
Your code should be able to read the file and print the result for each RPN in a new line.
Example of RPN: and your output should be This is a simple expression. More complex algebraic notations will be used to test your program like the one below.
Example algebraic notation:
Translated into RPN:
Note: Your code should be able to read the input file from the same folder which has your py file Do not hard code the path to the file in your laptopdesktop Use os to get the path and read the input file. Also, please take special care to process the lineending character correctly; for example, if you write the program on a Mac it should work correctly when graded using Windows and vice versa.
Extra credit question:
Write a separate program that can input an algebraic expression and convert it to RPN and then evaluate the RPN Print the RPN and the result in separate lines. The input file name will be inputRPNECtxt and it will have algebraic expressions.
Add at least one more operator unary subtraction, or modulo division, etc. You must document what operators you are adding. Add which ones to comments and make sure to include that as well in your submission
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started