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
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))
Comments
Leave a comment