{"record":{"id":"9af9be9c35b5fdb9","repo":"TheAlgorithms/Python","slug":"final-orbit-radius-must-be-greater-than-zero","errorCode":null,"errorMessage":"Final orbit radius must be greater than zero.","messagePattern":"Final orbit radius must be greater than zero\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"physics/orbital_transfer_work.py","lineNumber":62,"sourceCode":"    return f\"{work:.3e}\"\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n    print(\"Orbital transfer work calculator\\n\")\n\n    try:\n        M = float(input(\"Enter mass of central body (kg): \").strip())\n        if M <= 0:\n            r1 = float(input(\"Enter initial orbit radius (m): \").strip())\n        if r1 <= 0:\n            raise ValueError(\"Initial orbit radius must be greater than zero.\")\n\n        r2 = float(input(\"Enter final orbit radius (m): \").strip())\n        if r2 <= 0:\n            raise ValueError(\"Final orbit radius must be greater than zero.\")\n        m = float(input(\"Enter mass of orbiting object (kg): \").strip())\n        if m <= 0:\n            raise ValueError(\"Mass of the orbiting object must be greater than zero.\")\n        r1 = float(input(\"Enter initial orbit radius (m): \").strip())\n        r2 = float(input(\"Enter final orbit radius (m): \").strip())\n\n        result = orbital_transfer_work(M, m, r1, r2)\n        print(f\"Work done in orbital transfer: {result} Joules\")\n\n    except ValueError as e:\n        print(f\"Input error: {e}\")\n","sourceCodeStart":44,"sourceCodeEnd":74,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/orbital_transfer_work.py#L44-L74","documentation":"Raised in the __main__ interactive block of physics/orbital_transfer_work.py when the final orbit radius entered at the prompt is <= 0. As with the r1 check, the surrounding CLI re-reads r2 at line 67 after validation, so the checked value can be replaced by an unvalidated one before the calculation. The exception is caught by the local except ValueError and printed as 'Input error: ...'.","triggerScenarios":"Running the script directly and answering the 'Enter final orbit radius (m):' prompt (either at line 60 or the duplicate at line 67) with 0 or a negative number such as -7e6.","commonSituations":"Entering a descent target expressed as a negative delta; mixing up meters and kilometers so a value like 7000 (which is positive but below the central body surface) passes while 0 does not; piped stdin automation feeding empty lines that float() converts to a ValueError caught as 'Input error'.","solutions":["Enter a strictly positive final radius in meters, e.g. 7000000","Compute the radius (altitude + central body radius) before typing it in, rather than entering the altitude","Skip the CLI: import orbital_transfer_work() and validate r_final > 0 in your own code","If maintaining the script, delete the duplicate r1/r2 input calls at lines 66-67"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"r2 = float(input(\"Enter final orbit radius (m): \").strip())\nif r2 <= 0:\n    raise ValueError(f\"Final radius must be > 0, got {r2}\")","typeGuard":null,"tryCatchPattern":"try:\n    result = orbital_transfer_work(M, m, r1, r2)\nexcept ValueError as e:\n    print(f\"Input error: {e}\")","preventionTips":["Enter final radius in meters, strictly positive","Remember the CLI re-prompts for r1/r2 after validation (lines 66-67) — the re-entered values are what get used"],"tags":["physics","cli","user-input","valueerror","orbital-mechanics"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}