{"record":{"id":"c23eec50b86fe676","repo":"TheAlgorithms/Python","slug":"impossible-object-volume","errorCode":null,"errorMessage":"Impossible object volume","messagePattern":"Impossible object volume","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/archimedes_principle_of_buoyant_force.py","lineNumber":52,"sourceCode":"    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":34,"sourceCodeEnd":63,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/archimedes_principle_of_buoyant_force.py#L34-L63","documentation":"Raised by archimedes_principle when the volume argument is <= 0. The displaced-fluid volume must be strictly positive for the buoyant-force formula to be meaningful; zero or negative submerged volume is rejected. It is the second check, so a bad density raises first.","triggerScenarios":"Calling archimedes_principle(volume=0, ...) or archimedes_principle(volume=-2.5, ...), for example when an object is fully outside the fluid or a geometry computation returns 0.","commonSituations":"Volume computed from dimensions that are zero (degenerate shape) or negative due to an ordering bug (e.g. height computed as top - bottom with swapped inputs).","solutions":["Pass a positive submerged volume in m^3; double-check the submerged fraction if only part of the object is immersed","Fix upstream geometry: use abs() or reorder operands so length/height computations cannot go negative","Guard degenerate shapes before the call if a zero-volume object is possible in your domain"],"exampleFix":"# before\narchimedes_principle(fluid_density=997, volume=top - bottom, gravity=9.8)  # swapped -> negative\n\n# after\narchimedes_principle(fluid_density=997, volume=abs(top - bottom), gravity=9.8)","handlingStrategy":"validation","validationCode":"def valid_volume(volume) -> bool:\n    return volume > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compute volumes from dimensions with abs() or ordered operands to avoid sign flips","Reject degenerate (zero-dimension) shapes upstream"],"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"}