Python Program to Calculate Area of Triangle

Here we will write a program in Python to calculate Area of Triangle.

To find the area of triangle we need the sides of the triangle, if this program will only work if we have sides of triangle. So let’s see how to calculate area of triangle:

If ab and c are three sides of a triangle. Then using Herons formula,

s = (a+b+c)/2
area = √(s(s-a)*(s-b)*(s-c))

Python Program to Calculate Area of Triangle:

# Python Program to find the area of triangle

a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter 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)

OUTPUT:

Enter first side: 5
Enter second side: 6
Enter third side: 7
The area of the triangle is 14.70

Please comment for any concerns or corrections.