{"record":{"id":"70decff27ee5481b","repo":"TheAlgorithms/Python","slug":"area-parallelogram-only-accepts-non-negative-val","errorCode":null,"errorMessage":"area_parallelogram() only accepts non-negative values","messagePattern":"area_parallelogram\\(\\) only accepts non-negative values","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/area.py","lineNumber":387,"sourceCode":"    >>> area_parallelogram(1.6, 2.6)\r\n    4.16\r\n    >>> area_parallelogram(0, 0)\r\n    0\r\n    >>> area_parallelogram(-1, -2)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: area_parallelogram() only accepts non-negative values\r\n    >>> area_parallelogram(1, -2)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: area_parallelogram() only accepts non-negative values\r\n    >>> area_parallelogram(-1, 2)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: area_parallelogram() only accepts non-negative values\r\n    \"\"\"\r\n    if base < 0 or height < 0:\r\n        raise ValueError(\"area_parallelogram() only accepts non-negative values\")\r\n    return base * height\r\n\r\n\r\ndef area_trapezium(base1: float, base2: float, height: float) -> float:\r\n    \"\"\"\r\n    Calculate the area of a trapezium.\r\n\r\n    >>> area_trapezium(10, 20, 30)\r\n    450.0\r\n    >>> area_trapezium(1.6, 2.6, 3.6)\r\n    7.5600000000000005\r\n    >>> area_trapezium(0, 0, 0)\r\n    0.0\r\n    >>> area_trapezium(-1, -2, -3)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: area_trapezium() only accepts non-negative values\r\n    >>> area_trapezium(-1, 2, 3)\r","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/area.py#L369-L405","documentation":"area_parallelogram() raises this ValueError when base or height is negative. Both are physical measurements; the library enforces >= 0 before returning base * height. Note this function takes the perpendicular height, not a slanted side, so sign confusion here usually means bad input data rather than a geometry mistake.","triggerScenarios":"Calling area_parallelogram(base, height) with base < 0 or height < 0, e.g. area_parallelogram(-1, 2) or area_parallelogram(1, -2).","commonSituations":"Land-plot measurement imports with sign conventions; heights computed from coordinate projections that flip sign; -1 sentinels in legacy data files.","solutions":["Validate base >= 0 and height >= 0 before the call; fix the negative source value.","Normalize signed projections with abs() when only magnitude matters.","Clean imported data to replace negative sentinels with missing-value markers.","Catch ValueError for a friendly application-level message."],"exampleFix":"// before\narea = area_parallelogram(base, height)  # height from projection, may be < 0\n\n# after\narea = area_parallelogram(base, abs(height))","handlingStrategy":"validation","validationCode":"if base < 0 or height < 0:\n    raise ValueError(f'parallelogram base/height must be >= 0: {base}, {height}')\narea = area_parallelogram(base, height)","typeGuard":"def is_valid_parallelogram_dims(b: float, h: float) -> bool:\n    return b >= 0 and h >= 0","tryCatchPattern":"try:\n    area = area_parallelogram(base, height)\nexcept ValueError as e:\n    raise ValueError(f'invalid parallelogram input: {e}') from e","preventionTips":["Pass the perpendicular height, not a signed projection.","Normalize projections with abs() when only magnitude matters."],"tags":["python","math","geometry","validation","valueerror","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}