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 calledcalculatorpy that can calculate simple equations of any of the following forms:
x op y
x op y op z
x opy op z
The user must enter each equation as one single string, eg and
Your program should not ask for the different parts of an equation separately, eg "what's the first operand", "what's the operator", and "what's the second operand".
Assume the user will only enter nonnegative numbers.
The possible operators are
is exponentiationNote that the divisor cannot be Your program should handle it gracefully, ie 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", ie NO red errors.
Requirements
Your code should be well organized using functions, ie
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,ie
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
