triangle

Triangle program core definitions.

 1"""Triangle program core definitions."""
 2import math
 3
 4
 5def trianglePerimeter(a, b, c):
 6    """:return: Perimeter of the triangle."""
 7    return a + b + c
 8
 9
10def triangleArea(a, b, c):
11    """:return: Area of the triangle."""
12    s = (a + b + c) / 2
13    area = math.sqrt(s * (s - a) * (s - b) * (s - c))
14    return area
15
16
17def constructability(a, b, c):
18    """:return: Constructability of the triangle."""
19    return (a + b > c) and (b + c > a) and (c + a > b)
20
21
22def triangleOrthogonality(leg1, leg2, hypotenuse):
23    """:return: Orthogonality of the triangle."""
24    return math.pow(hypotenuse, 2) == math.pow(leg1, 2) + math.pow(leg2, 2)
def trianglePerimeter(a, b, c):
6def trianglePerimeter(a, b, c):
7    """:return: Perimeter of the triangle."""
8    return a + b + c
Returns

Perimeter of the triangle.

def triangleArea(a, b, c):
11def triangleArea(a, b, c):
12    """:return: Area of the triangle."""
13    s = (a + b + c) / 2
14    area = math.sqrt(s * (s - a) * (s - b) * (s - c))
15    return area
Returns

Area of the triangle.

def constructability(a, b, c):
18def constructability(a, b, c):
19    """:return: Constructability of the triangle."""
20    return (a + b > c) and (b + c > a) and (c + a > b)
Returns

Constructability of the triangle.

def triangleOrthogonality(leg1, leg2, hypotenuse):
23def triangleOrthogonality(leg1, leg2, hypotenuse):
24    """:return: Orthogonality of the triangle."""
25    return math.pow(hypotenuse, 2) == math.pow(leg1, 2) + math.pow(leg2, 2)
Returns

Orthogonality of the triangle.