Skip to content

Conversation

@kelvinwaringa
Copy link

Description

This PR adds a new maths/division.py file with a divide_numbers() function that includes explicit input validation for zero denominators. This addresses issue #13845.

Changes

  • Created maths/division.py with divide_numbers() function
  • Added explicit validation for zero denominator with clear error message
  • Included comprehensive docstring with examples and doctests
  • Followed repository coding standards with type hints

Benefits

  • Provides clearer error messages for beginners learning about error handling
  • Aligns with educational best practices for the repository
  • Makes the function more robust and user-friendly

Testing

The function includes doctests that cover:

  • Normal division cases (positive, negative, decimal results)
  • Zero numerator case
  • Zero denominator error case

Related Issue

Fixes #13845

kelvinwaringa and others added 2 commits November 17, 2025 18:21
- Create maths/division.py with divide_numbers() function
- Add explicit validation for zero denominator
- Include comprehensive docstring with examples
- Add doctests for various cases including error handling
- Follow repository coding standards with type hints

Fixes TheAlgorithms#13845
@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Nov 17, 2025
- Fix E501: Break long line in docstring to stay within 88 chars
- Fix W293: Remove trailing whitespace from blank lines
@algorithms-keeper algorithms-keeper bot added the require descriptive names This PR needs descriptive function and/or variable names label Nov 17, 2025
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

- Rename parameter 'a' to 'numerator' for clarity
- Rename parameter 'b' to 'denominator' for clarity
- Update all references in function body and docstring
@algorithms-keeper algorithms-keeper bot added tests are failing Do not merge until tests pass and removed require descriptive names This PR needs descriptive function and/or variable names tests are failing Do not merge until tests pass labels Nov 17, 2025
Copy link
Contributor

@mindaugl mindaugl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great

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

Labels

awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add input validation for division by zero in divide_numbers()

2 participants