TheAlgorithms/Python · error · ValueError

The radius is always a positive number

Error message

The radius is always a positive number

What it means

Error "The radius is always a positive number" thrown in TheAlgorithms/Python.

Source

Thrown at physics/coulombs_law.py:35

def coulombs_law(q1: float, q2: float, radius: float) -> float:
    """
    Calculate the electrostatic force of attraction or repulsion
    between two point charges

    >>> coulombs_law(15.5, 20, 15)
    12382849136.06
    >>> coulombs_law(1, 15, 5)
    5392531075.38
    >>> coulombs_law(20, -50, 15)
    -39944674632.44
    >>> coulombs_law(-5, -8, 10)
    3595020716.92
    >>> coulombs_law(50, 100, 50)
    17975103584.6
    """
    if radius <= 0:
        raise ValueError("The radius is always a positive number")
    return round(((8.9875517923 * 10**9) * q1 * q2) / (radius**2), 2)


if __name__ == "__main__":
    import doctest

    doctest.testmod()

View on GitHub (pinned to f5988cc097)

Solutions

  1. Pass a positive radius.

When it happens

Trigger: Thrown at physics/coulombs_law.py:35 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/83455eca930a2cb8. Report an issue: GitHub.