{"record":{"id":"c08f079554ffe236","repo":"TheAlgorithms/Python","slug":"impossible-fluid-density","errorCode":null,"errorMessage":"Impossible fluid density","messagePattern":"Impossible fluid density","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/archimedes_principle_of_buoyant_force.py","lineNumber":50,"sourceCode":"    6844.061035\n    >>> archimedes_principle(fluid_density=997, volume=-0.7)\n    Traceback (most recent call last):\n        ...\n    ValueError: Impossible object volume\n    >>> archimedes_principle(fluid_density=0, volume=0.7)\n    Traceback (most recent call last):\n        ...\n    ValueError: Impossible fluid density\n    >>> archimedes_principle(fluid_density=997, volume=0.7, gravity=0)\n    0.0\n    >>> archimedes_principle(fluid_density=997, volume=0.7, gravity=-9.8)\n    Traceback (most recent call last):\n        ...\n    ValueError: Impossible gravity\n    \"\"\"\n\n    if fluid_density <= 0:\n        raise ValueError(\"Impossible fluid density\")\n    if volume <= 0:\n        raise ValueError(\"Impossible object volume\")\n    if gravity < 0:\n        raise ValueError(\"Impossible gravity\")\n\n    return fluid_density * gravity * volume\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":32,"sourceCodeEnd":63,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/archimedes_principle_of_buoyant_force.py#L32-L63","documentation":"Raised by archimedes_principle when fluid_density is <= 0. The buoyant force formula (density * gravity * volume) requires a positive fluid density; zero density would mean no fluid, and negative density is unphysical. This is the first of three ordered validation checks (density, volume, gravity).","triggerScenarios":"Calling archimedes_principle(fluid_density=-997, ...) or archimedes_principle(fluid_density=0, ...). Gravity=0 is allowed (returns 0.0, e.g. orbit); only density and volume must be strictly positive.","commonSituations":"Passing densities in wrong units or sign conventions, defaulting density to 0 in a config struct, or vacuum scenarios encoded as 0 density — all rejected by design.","solutions":["Pass a positive fluid density in kg/m^3 (e.g. 997 for water, 1.225 for air at sea level)","Check config defaults: an unset density of 0 will raise","For vacuum/free-fall scenarios, keep density/volume positive and set gravity=0 instead (that path is supported)"],"exampleFix":"# before\narchimedes_principle(fluid_density=0, volume=0.7, gravity=9.8)  # ValueError\n\n# after\narchimedes_principle(fluid_density=997, volume=0.7, gravity=9.8)","handlingStrategy":"validation","validationCode":"def valid_fluid_density(fluid_density) -> bool:\n    return fluid_density > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use realistic densities in kg/m^3 (water 997, air 1.225) and never leave 0 defaults","For free-fall scenarios set gravity=0 rather than density=0"],"tags":["physics","buoyancy","argument-validation","range-check"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}