Answer to Question #187807 in Python for Ali

Question #187807

Write an interactive Python calculator program. The program should allow the user to type in a mathematical expression, and then it should evaluate and print the resultant value of the expression. Include a loop so that the user can perform many calculations one after the other.

To quit early, the user can make the program crash by typing a bad expression (e.g., (2 + 2) * 5 ! 4) (You’ll learn better ways of terminating interactive programs in later lessons) or a user can terminate it simply by entering Quit as sentinel value


1
Expert's answer
2021-05-01T14:10:03-0400
print('Implementing a Simple Calculator Emulation')
print('The program exits when an incorrect expression is entered or "Quit"')
while True:
    term_math = input('Enter a mathematical expression:')
    if term_math.lower() == 'quit':
        break
    print('Result :',eval(term_math))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS