{"record":{"id":"e07f6f82b2763fd5","repo":"TheAlgorithms/Python","slug":"monogons-and-digons-are-not-polygons-in-the-euclid","errorCode":null,"errorMessage":"Monogons and Digons are not polygons in the Euclidean space","messagePattern":"Monogons and Digons are not polygons in the Euclidean space","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/check_polygon.py","lineNumber":33,"sourceCode":"    >>> check_polygon([3, 7, 13, 2])\n    False\n    >>> 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":15,"sourceCodeEnd":45,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/check_polygon.py#L15-L45","documentation":"Raised by check_polygon() in maths/check_polygon.py when the input list of side lengths has fewer than 2 entries. The function decides whether side lengths can form a polygon; with 0 or 1 sides there is no polygon in Euclidean space (a monogon/digon is degenerate), so it raises ValueError before checking the triangle-inequality-style condition.","triggerScenarios":"Calling check_polygon([]) (empty list) or check_polygon([5]) (single side). The guard is len(nums) < 2.","commonSituations":"Feeding an empty dataset or a filtered list that ended up empty into a geometry pipeline; parsing side lengths from user input or a file where only one value was extracted; forgetting that a triangle needs 3 sides and testing with fewer.","solutions":["Ensure the input list contains at least 2 side lengths (in practice at least 3 for a real polygon) before calling.","Fix the upstream collection step that produced an empty or single-element list of side lengths.","Validate parsed input (e.g. after split/strip of a user string) before passing to check_polygon."],"exampleFix":"# before\nsides = []\ncheck_polygon(sides)  # ValueError\n\n# after\nsides = [3, 7, 13, 2]\nif len(sides) < 3:\n    raise SystemExit('need at least 3 side lengths')\ncheck_polygon(sides)","handlingStrategy":"validation","validationCode":"if len(sides) < 3:\n    raise ValueError(f'need at least 3 sides, got {len(sides)}')","typeGuard":"def is_polygon_input(nums) -> bool:\n    return isinstance(nums, (list, tuple)) and len(nums) >= 3","tryCatchPattern":"try:\n    check_polygon(sides)\nexcept ValueError as e:\n    if 'Monogons' in str(e):\n        sides = collect_more_sides()  # re-prompt / re-parse\n    else:\n        raise","preventionTips":["Treat an empty or tiny side list as invalid input at parse time, not inside the math call.","Distinguish 'not enough sides' from 'bad side values' in your own error messages."],"tags":["maths","geometry","validation","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}