Python program to find the area of a triangle

Formula to find area of triangle

$$ \text{Semi-perimeter (s)} = \frac{(a+b+c)}{2} $$

$$ \text{Area of a triangle} = {\sqrt{(s(s-a)(s-b)(s-c))}} $$

where a, b, and c are length of three sides

1import math 2 3# Python Program to find the area of triangle 4a = 20 5b = 30 6c = 45 7 8# calculate the semi-perimeter 9s = (a + b + c) / 2 10 11# calculate the area 12area = math.sqrt((s*(s-a)*(s-b)*(s-c))) 13print('The area of the triangle: %0.2f' %area)

Output:

1The area of the triangle: 239.06