Answer to Question #187850 in Python for Ali

Question #187850

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-03T18:15:59-0400
print('Enter incorrect expression or "Quit" to exit the program')
while True:
    exp= input('Enter a mathematical expression:')
    if exp.lower() == 'quit':
        break
    print('Result :',eval(exp))

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