Python Area of Triangle With Three Sides Formula – This Python program will input the three sides of a triangle. It will use the following formula to calculate the area of the triangle.

### Heron’s Formula

The area of a triangle can be calculated by using Heron’s formula if we only know the length of all three sides of the triangle.

In this formula , we need the value of three sides of triangle and the value of s where s is the semi-perimeter.

s = ( a + b + c ) / 2

Then we will calculate area of the triangle by the following formula:

area = (s*(s-a)*(s-b)*(s-c))**0.5

Where ** represents raised to the power 0.5 means it will give us square root of the value.

### Source Code of area of triangle program

# Python program to find area of # triangle when three sides are given # Input the lengths of three sides of the triangle a, b and c: a = float(input('Enter first side a: ')) b = float(input('Enter second side b: ')) c = float(input('Enter third side c: ')) # calculate the semi-perimeter using the formula s = (a + b + c) / 2.0 # calculate the area using Heron's formula area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 # display the result upto 2 decimal places print('The area of the triangle is %0.2f' %area)

You may also like:

Python GUI Program Find Triangle area

Program Area of Triangle Algorithm Flowchart

### Output from a Sample Run

Enter first side a: 5 Enter second side b: 4 Enter third side c: 6 The area of the triangle is 9.92 2nd Output Enter first side a: 7 Enter second side b: 4 Enter third side c: 8 The area of the triangle is 14.00

### Python Area of Triangle Using a user defined function

# Python program to find area of # triangle when three sides are given # Input the lengths of three sides of the triangle a, b and c: def area_of_triangle(a,b,c): # calculate the semi-perimeter using the formula s = (a + b + c) / 2.0 # calculate the area using Heron's formula area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 # display the result upto 2 decimal places print('The area of the triangle is %0.2f' %area) a = float(input('Enter first side a: ')) b = float(input('Enter second side b: ')) c = float(input('Enter third side c: ')) area_of_triangle(a,b,c)

635 total views, 1 views today