From 5f53d14887568add20b04b9fdb94cb37d93b07fa Mon Sep 17 00:00:00 2001 From: mohitkumar188 Date: Mon, 14 Sep 2026 12:03:52 +0530 Subject: [PATCH] Update check_polygon.py Fix polygon side validation and add digon doctest --- maths/check_polygon.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/maths/check_polygon.py b/maths/check_polygon.py index 1e8dce7183ad..db6a6d55b3e1 100644 --- a/maths/check_polygon.py +++ b/maths/check_polygon.py @@ -17,25 +17,28 @@ def check_polygon(nums: list[float]) -> bool: >>> check_polygon([1, 4.3, 5.2, 12.2]) False >>> nums = [3, 7, 13, 2] - >>> _ = check_polygon(nums) # Run function, do not show answer in output - >>> nums # Check numbers are not reordered + >>> _ = check_polygon(nums) + >>> nums [3, 7, 13, 2] >>> check_polygon([]) Traceback (most recent call last): ... ValueError: Monogons and Digons are not polygons in the Euclidean space + >>> check_polygon([4, 5]) + Traceback (most recent call last): + ... + ValueError: Monogons and Digons are not polygons in the Euclidean space >>> check_polygon([-2, 5, 6]) Traceback (most recent call last): ... ValueError: All values must be greater than 0 """ - if len(nums) < 2: + if len(nums) < 3: raise ValueError("Monogons and Digons are not polygons in the Euclidean space") if any(i <= 0 for i in nums): raise ValueError("All values must be greater than 0") - copy_nums = nums.copy() - copy_nums.sort() - return copy_nums[-1] < sum(copy_nums[:-1]) + sorted_nums = sorted(nums) + return sorted_nums[-1] < sum(sorted_nums[:-1]) if __name__ == "__main__":