Question: i created an calculator code thats running but isnt letting me run any operations of addition,subtracting or nothing it just gives this one line when


Problem 1) Simple Calculator: In Python, implement a simple calculator that does the following operations: summation, subtraction, multiplication, division, mod, power, exp, natural log, and abs. a) Follow the instructions below: To work with the calculator, the program asks the user to enter the first number, then the operation, and finally the second number if required. Your code has to recognize the need for the second number and ask for it if required. After performing one operation, the calculator prints the output of the operation. After performing one operation, the calculator must not exit. It has to start again and ready for the next operation. The calculator will be closed if the user writes 'x' as an input. Use functions to perform the operations and the appropriate conditions to prevent common errors such as entering characters as one of the numbers etc. b) Run your code and provide the results for at least one example per operation. import re print ("Our Magical Calculator") print("Type to exit ") previous=0 run= True D 11 def do_math() : global run global previous equation="" if previous==0: equation=input("Enter Equation:") else: equation=input(str(previous)) if equation=='x': print("Good Bye!") run= False if previous==0: equation=input("Enter Equation:") else: equation=input(str(previous)) if equation=='x': print("Good Bye!") run= False else: equation= re. sub('[a-zA-Z, .:(" "#&@]','', equation) if previous==0: previous-eval(equation) else: previous eval(str(previous)+equation) while run: do_math() O Our Magical Calculator Type to exit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
