{"record":{"id":"e90a4530b1002cfc","repo":"TheAlgorithms/Python","slug":"radius-cannot-be-zero","errorCode":null,"errorMessage":"Radius cannot be zero.","messagePattern":"Radius cannot be zero\\.","errorType":"validation","errorClass":"ZeroDivisionError","httpStatus":null,"severity":"error","filePath":"physics/escape_velocity.py","lineNumber":45,"sourceCode":"\n    Examples:\n        >>> escape_velocity(mass=5.972e24, radius=6.371e6)  # Earth\n        11185.978\n        >>> escape_velocity(mass=7.348e22, radius=1.737e6)  # Moon\n        2376.307\n        >>> escape_velocity(mass=1.898e27, radius=6.9911e7)  # Jupiter\n        60199.545\n        >>> escape_velocity(mass=0, radius=1.0)\n        0.0\n        >>> escape_velocity(mass=1.0, radius=0)\n        Traceback (most recent call last):\n            ...\n        ZeroDivisionError: Radius cannot be zero.\n    \"\"\"\n    gravitational_constant = 6.67430e-11  # m^3 kg^-1 s^-2\n\n    if radius == 0:\n        raise ZeroDivisionError(\"Radius cannot be zero.\")\n\n    velocity = math.sqrt(2 * gravitational_constant * mass / radius)\n    return round(velocity, 3)\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n    print(\"Calculate escape velocity of a celestial body...\\n\")\n\n    try:\n        mass = float(input(\"Enter mass of the celestial body (in kgs): \").strip())\n        radius = float(input(\"Enter radius from the center of mass (in ms): \").strip())\n\n        velocity = escape_velocity(mass=mass, radius=radius)\n        print(f\"Escape velocity is {velocity} m/s\")\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/escape_velocity.py#L27-L63","documentation":"Error \"Radius cannot be zero.\" thrown in TheAlgorithms/Python.","triggerScenarios":"Thrown at physics/escape_velocity.py:45 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-zero radius."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}