Hints
Use a Loop:
Implement a
while
loop to continuously prompt the user for input until they choose to exit.
Utilize
eval()
:Use the
eval()
function to evaluate the mathematical expression entered by the user. Be cautious about input validation.
Error Handling:
Use
try-except
blocks around theeval()
call to handle potential errors, such as division by zero or invalid input.
User Input:
Prompt the user to enter a mathematical expression and provide a clear option to exit (e.g., type 'exit').
Print Results:
After evaluating the expression, print the result back to the user in a clear format.