{"record":{"id":"c6754bb74801f226","repo":"TheAlgorithms/Python","slug":"all-values-must-be-greater-than-0","errorCode":null,"errorMessage":"All values must be greater than 0","messagePattern":"All values must be greater than 0","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/check_polygon.py","lineNumber":35,"sourceCode":"    >>> check_polygon([1, 4.3, 5.2, 12.2])\n    False\n    >>> nums = [3, 7, 13, 2]\n    >>> _ = check_polygon(nums) #   Run function, do not show answer in output\n    >>> nums #  Check numbers are not reordered\n    [3, 7, 13, 2]\n    >>> check_polygon([])\n    Traceback (most recent call last):\n        ...\n    ValueError: Monogons and Digons are not polygons in the Euclidean space\n    >>> check_polygon([-2, 5, 6])\n    Traceback (most recent call last):\n        ...\n    ValueError: All values must be greater than 0\n    \"\"\"\n    if len(nums) < 2:\n        raise ValueError(\"Monogons and Digons are not polygons in the Euclidean space\")\n    if any(i <= 0 for i in nums):\n        raise ValueError(\"All values must be greater than 0\")\n    copy_nums = nums.copy()\n    copy_nums.sort()\n    return copy_nums[-1] < sum(copy_nums[:-1])\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n","sourceCodeStart":17,"sourceCodeEnd":45,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/check_polygon.py#L17-L45","documentation":"Raised by check_polygon() in maths/check_polygon.py when any value in the input list is <= 0. Side lengths of a polygon must be strictly positive for the polygon-inequality check (largest side < sum of the rest) to be meaningful; a zero or negative 'length' is geometrically invalid, so the function raises ValueError.","triggerScenarios":"Calling check_polygon([-2, 5, 6]) or check_polygon([0, 4, 4]) — any list containing a zero or negative number. The guard is any(i <= 0 for i in nums).","commonSituations":"Signed distances or deltas passed where magnitudes were intended; sensor data with zeros/NaNs represented as 0; typos such as -2 instead of 2; unvalidated user or CSV input with missing values parsed as negative sentinels.","solutions":["Filter or reject non-positive values before calling: all(s > 0 for s in sides).","Take absolute values only if negative values are genuinely signed measurements and magnitude is what you meant.","Fix data entry / parsing so side lengths are always positive reals."],"exampleFix":"# before\ncheck_polygon([-2, 5, 6])  # ValueError\n\n# after\nsides = [abs(s) for s in [-2, 5, 6]]\nif any(s <= 0 for s in sides):\n    raise ValueError('side lengths must be positive')\ncheck_polygon(sides)","handlingStrategy":"validation","validationCode":"if not nums or any(s <= 0 for s in nums):\n    raise ValueError(f'side lengths must be positive: {nums}')","typeGuard":"def are_positive_sides(nums) -> bool:\n    return len(nums) >= 3 and all(isinstance(s, (int, float)) and s > 0 for s in nums)","tryCatchPattern":"try:\n    check_polygon(sides)\nexcept ValueError as e:\n    if 'greater than 0' in str(e):\n        sides = [abs(s) for s in sides if s != 0]  # only if magnitudes were intended\n    else:\n        raise","preventionTips":["Reject zeros and negatives at data-ingest time (CSV/user input) rather than deep in geometry code.","Watch for sentinel values like -1 or 0 used for 'missing' in legacy datasets."],"tags":["maths","geometry","validation","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}