Question: Write a program called calculator . py that can calculate simple equations of any of the following forms: x op y ( x op 1

Write a program calledcalculator.py that can calculate simple equations of any of the following forms:
x op y
(x op1 y) op2 z
x op1(y op2 z)
The user must enter each equation as one single string, e.g.,"2+3" and "(2+4)**2".
Your program should not ask for the different parts of an equation separately, e.g., "what's the first operand", "what's the operator", and "what's the second operand".
Assume the user will only enter non-negative numbers.
The possible operators are +,-,*,/,**
** is exponentiationNote that the divisor cannot be 0. Your program should handle it gracefully, i.e., report it and ask the user to try again. (See examples for more details)
The user may enter any number of empty spaces anywhere in the equation.
Print the equation the user enters along with the result. If the equation contains parentheses, print the middle step equation and result as well. (See examples for more details.)
Finally, your program should keep asking the user for a new equation until the user enters "Done". When the user enters Done, your program should terminate "naturally", i.e., NO red errors.
Requirements
Your code should be well organized using functions, i.e.
Everything should be inside some function. No global variables.Define at least two functions, including the main() function. So just one more function other than main() is sufficient.
You arenot allowed to import any module,i.e.
No "import ..." or "from ... import ..." or anything for the same purpose.
You arenot allowed to use the eval() function or anything similar.
All the outputs from your program should be printed nicely and readable.

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 Programming Questions!