-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Description
The calculator does not handle division by zero correctly. When the user attempts to divide a number by 0, the application crashes instead of displaying an error message.
Steps to reproduce
Run the application.
Enter a number (e.g. 5).
Press the division (/) button.
Enter 0.
Press the equals (=) button.
Expected behavior
The calculator should display the string "Error" in the input field and continue running normally.
Actual behavior
The application crashes due to a ZeroDivisionError raised during expression evaluation.
Relevant code
File: test.calc.py
Method: evaluate_expression
The issue occurs because eval(expression) is called without handling ZeroDivisionError.
Suggested fix
Catch ZeroDivisionError in the evaluate_expression method and display "Error" instead of allowing the application to crash.
Environment
Python 3.x
Tkinter GUI