Skip to content

Add input validation for division by zero in divide_numbers() #13845

Description

@Vedavyasa21

Feature description

Currently, the divide_numbers(a, b) function in maths/division.py performs basic division but lacks input validation for zero denominators.
While Python’s built-in behavior raises a ZeroDivisionError, adding explicit validation would make the function more robust and user-friendly — especially for beginners using this repository to learn algorithms.

This feature would ensure that the function provides clearer feedback and better error handling, aligning with educational best practices

def divide_numbers(a, b):
    if b == 0:
        raise ValueError("Cannot divide by zero. Please provide a non-zero denominator.")
    return a / b

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis PR modified some existing files

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions