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