Skip to content

Division by zero crashes the calculator instead of showing error #4

@giannisster

Description

@giannisster

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions