TheAlgorithms/Python · error · ValueError

The mass of the body cannot be negative

Error message

The mass of the body cannot be negative

What it means

Error "The mass of the body cannot be negative" thrown in TheAlgorithms/Python.

Source

Thrown at physics/centripetal_force.py:40


def centripetal(mass: float, velocity: float, radius: float) -> float:
    """
    The Centripetal Force formula is given as: (m*v*v)/r

    >>> round(centripetal(15.5,-30,10),2)
    1395.0
    >>> round(centripetal(10,15,5),2)
    450.0
    >>> round(centripetal(20,-50,15),2)
    3333.33
    >>> round(centripetal(12.25,40,25),2)
    784.0
    >>> round(centripetal(50,100,50),2)
    10000.0
    """
    if mass < 0:
        raise ValueError("The mass of the body cannot be negative")
    if radius <= 0:
        raise ValueError("The radius is always a positive non zero integer")
    return (mass * (velocity) ** 2) / radius


if __name__ == "__main__":
    import doctest

    doctest.testmod(verbose=True)

View on GitHub (pinned to f5988cc097)

Solutions

  1. Pass a non-negative mass.

When it happens

Trigger: Thrown at physics/centripetal_force.py:40 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/a3396a774caeea37. Report an issue: GitHub.