Question: Using Python!!!! You will be writing a stack-based calculator program. How a stack-based calculator works is as follows: The user can input an integer or

Using Python!!!!

You will be writing a stack-based calculator program. How a stack-based calculator works is as follows:

The user can input an integer or an operation. If an integer is entered, it is added to a stack (For this stack, we can use a simple list.) When an operation is entered, one of two things can happen:

IF this is the first time an operation has been given then pop the first two numbers given (i.e. pop from the top of the stack), and perform the operation with those two numbers, and store this result at the top of the stack.

Otherwise, perform the operation on the result of the last operation and the last entered integer. (i.e. pop the top two integers from the stack.)

As a hint, Python lists have a pop() method that returns the value from the top of the stack and push() that puts a value at the top of the stack.

The program will always be given valid input.

Note that many integers can be entered before an operation is given.

EXAMPLES:

out:

VALUE OR OPERATION: 

in:

5 

out:

LAST VALUE: 5 VALUE OR OPERATION: 

in:

6 

out:

LAST VALUE: 6 VALUE OR OPERATION: 

in:

+ 

out:

LAST VALUE: 11 VALUE OR OPERATION: 

in:

done 

out:

EXITING 

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!