Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions maths/division.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
This module provides a function for dividing two numbers with proper input validation.

The divide_numbers function includes validation to prevent division by zero errors,
providing clear error messages for better user experience.
"""


def divide_numbers(a: float, b: float) -> float:

Choose a reason for hiding this comment

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

Please provide descriptive name for the parameter: a

Please provide descriptive name for the parameter: b

"""
Divide two numbers with input validation for zero denominator.

Check failure on line 12 in maths/division.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

maths/division.py:12:1: W293 Blank line contains whitespace
Args:
a: The numerator (dividend)
b: The denominator (divisor)

Check failure on line 16 in maths/division.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

maths/division.py:16:1: W293 Blank line contains whitespace
Returns:
float: The result of a divided by b

Check failure on line 19 in maths/division.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

maths/division.py:19:1: W293 Blank line contains whitespace
Raises:
ValueError: If b is zero

Check failure on line 22 in maths/division.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

maths/division.py:22:1: W293 Blank line contains whitespace
Examples:
>>> divide_numbers(10, 2)
5.0
>>> divide_numbers(15, 3)
5.0
>>> divide_numbers(10, 0)
Traceback (most recent call last):
...
ValueError: Cannot divide by zero. Please provide a non-zero denominator.
"""
if b == 0:
raise ValueError("Cannot divide by zero. Please provide a non-zero denominator.")

Check failure on line 34 in maths/division.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

maths/division.py:34:89: E501 Line too long (89 > 88)
return a / b


if __name__ == "__main__":
import doctest

Check failure on line 40 in maths/division.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

maths/division.py:40:1: W293 Blank line contains whitespace
doctest.testmod()
Loading