Skip to content

Commit 5f53d14

Browse files
committed
Update check_polygon.py
Fix polygon side validation and add digon doctest
1 parent ca133c7 commit 5f53d14

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

maths/check_polygon.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,28 @@ def check_polygon(nums: list[float]) -> bool:
1717
>>> check_polygon([1, 4.3, 5.2, 12.2])
1818
False
1919
>>> nums = [3, 7, 13, 2]
20-
>>> _ = check_polygon(nums) # Run function, do not show answer in output
21-
>>> nums # Check numbers are not reordered
20+
>>> _ = check_polygon(nums)
21+
>>> nums
2222
[3, 7, 13, 2]
2323
>>> check_polygon([])
2424
Traceback (most recent call last):
2525
...
2626
ValueError: Monogons and Digons are not polygons in the Euclidean space
27+
>>> check_polygon([4, 5])
28+
Traceback (most recent call last):
29+
...
30+
ValueError: Monogons and Digons are not polygons in the Euclidean space
2731
>>> check_polygon([-2, 5, 6])
2832
Traceback (most recent call last):
2933
...
3034
ValueError: All values must be greater than 0
3135
"""
32-
if len(nums) < 2:
36+
if len(nums) < 3:
3337
raise ValueError("Monogons and Digons are not polygons in the Euclidean space")
3438
if any(i <= 0 for i in nums):
3539
raise ValueError("All values must be greater than 0")
36-
copy_nums = nums.copy()
37-
copy_nums.sort()
38-
return copy_nums[-1] < sum(copy_nums[:-1])
40+
sorted_nums = sorted(nums)
41+
return sorted_nums[-1] < sum(sorted_nums[:-1])
3942

4043

4144
if __name__ == "__main__":

0 commit comments

Comments
 (0)