{"record":{"id":"e2f9d163186d1fff","repo":"TheAlgorithms/Python","slug":"atmospheric-pressure-can-not-be-negative","errorCode":null,"errorMessage":"Atmospheric Pressure can not be negative !","messagePattern":"Atmospheric Pressure can not be negative !","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/altitude_pressure.py","lineNumber":45,"sourceCode":"    105.47836610778828\n    >>> get_altitude_at_pressure(pressure=101_325)\n    0.0\n    >>> get_altitude_at_pressure(pressure=80_000)\n    1855.873388064995\n    >>> get_altitude_at_pressure(pressure=201_325)\n    Traceback (most recent call last):\n      ...\n    ValueError: Value Higher than Pressure at Sea Level !\n    >>> get_altitude_at_pressure(pressure=-80_000)\n    Traceback (most recent call last):\n      ...\n    ValueError: Atmospheric Pressure can not be negative !\n    \"\"\"\n\n    if pressure > 101325:\n        raise ValueError(\"Value Higher than Pressure at Sea Level !\")\n    if pressure < 0:\n        raise ValueError(\"Atmospheric Pressure can not be negative !\")\n    return 44_330 * (1 - (pressure / 101_325) ** (1 / 5.5255))\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":27,"sourceCodeEnd":53,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/altitude_pressure.py#L27-L53","documentation":"Raised by get_altitude_at_pressure when the supplied pressure is negative. Atmospheric pressure is physically non-negative, and the fractional power in the barometric formula would be undefined for negative operands, so the guard runs after the sea-level-maximum check.","triggerScenarios":"Calling get_altitude_at_pressure(pressure=-80_000) or passing any negative pressure value, e.g. sensor readings that encode error states as negative numbers.","commonSituations":"Uninitialized or faulting pressure sensors reporting negative sentinel values, or signed-unit mistakes where a converted value flips sign.","solutions":["Validate sensor/config data and reject or replace negative pressure readings before the call","Check for sentinel values (e.g. -1, -9999) that instruments use to signal errors"],"exampleFix":"# before\nget_altitude_at_pressure(pressure=sensor_reading)  # -80000 -> ValueError\n\n# after\nif sensor_reading is not None and sensor_reading >= 0:\n    altitude = get_altitude_at_pressure(pressure=sensor_reading)","handlingStrategy":"validation","validationCode":"def plausible_pressure(pressure_pa) -> bool:\n    return pressure_pa >= 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat negative sensor readings as instrument faults and discard them before computation","Watch for sentinel values like -1 or -9999 in data feeds"],"tags":["physics","pressure","sensor-data","range-check"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}