We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5485418 commit 6708bf5Copy full SHA for 6708bf5
maths/check_polygon.py
@@ -0,0 +1,31 @@
1
+from typing import List
2
+
3
4
+def check_polygon(nums: List) -> bool:
5
+ """
6
+ Takes list of possible side lengths and determines whether a
7
+ two-dimensional polygon with such side lengths can exist.
8
9
+ Returns a boolean value for the < comparison
10
+ of the largest side length with sum of the rest.
11
+ Wiki: https://en.wikipedia.org/wiki/Triangle_inequality
12
13
+ >>> check_polygon([6, 10, 5])
14
+ True
15
+ >>> check_polygon([3, 7, 13, 2])
16
+ False
17
+ >>> check_polygon([])
18
+ Traceback (most recent call last):
19
+ ...
20
+ ValueError: List is invalid
21
22
+ if not nums:
23
+ raise ValueError("List is invalid")
24
+ nums.sort()
25
+ return nums.pop() < sum(nums)
26
27
28
+if __name__ == "__main__":
29
+ import doctest
30
31
+ doctest.testmod()
0 commit comments