AREA OF A TRIANGLE IN PYTHON
In geometry, Heron’s formula, named after Hero of Alexandria, gives the area of a triangle by requiring no arbitrary choice of side as base or vertex as origin.
Heron’s formula states that the area of a triangle whose sides have lengths a, b, and c is where s is the semi-perimeter of the triangle; that is,
Program
# Python Program to find the area of triangle
#Take inputs from the user
a = float(input(‘Enter the first side: ‘))
b = float(input(‘Enter the second side: ‘))
c = float(input(‘Enter the third side: ‘))
# calculate the semi-perimeter
s = (a + b + c) / 2
# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print(‘The area of the triangle is %0.2f’ %area)
input(“Press Enter to Exit”)
Output