Answered step by step
Verified Expert Solution
Link Copied!

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 4 operators +,-,*,/.
Input numbers will be single digits.
The input will be in postfix notation.
The input will be provided in a text file called input_RPN.txt.
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: 42+ and your output should be 6. This is a simple expression. More complex algebraic notations will be used to test your program like the one below.
Example algebraic notation: (4+2*5)/(1+3*2)
Translated into RPN: 425*+132*+/
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 laptop/desktop. Use os to get the path and read the input file. Also, please take special care to process the line-ending 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 input_RPN_EC.txt 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions