Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

calculator.py crashes on division by zero #824

@JAHNAVI-YERRAMSETTI

Description

@JAHNAVI-YERRAMSETTI

###📌 Problem
When using the calculator script, the program crashes if the user tries to divide by zero.

💥 Steps to Reproduce

  1. Run calculator.py
  2. Choose the division operation
  3. Enter any number (e.g., 10) and then 0

❗Actual Behavior

Program crashes with a ZeroDivisionError.

✅ Expected Behavior

The script should catch this error and show a user-friendly message like:
"Error: You cannot divide by zero."

🛠️ Suggested Fix

Wrap the division operation in a try-except block to catch ZeroDivisionError.

try:
    result = a / b
except ZeroDivisionError:
    print("Error: Cannot divide by zero.")

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