Python Program to Calculate the Area of Triangle

This Python program shows how you can calculate the area of a triangle in python and display it using the python’s print method.

How to Calculate the area if a triangle in Python?

Assume that you have three variables side1,side2 and side3 which refers to the three sides of a triangle. The area of the triangle is calculated with the formula as shown below.

area = SQRT((peri(peri-side1)(peri-side2)(peri-side3)))

Where perimiter ,

peri = (side1+side2+side3)/2

Python Code

# Python Program to find the area of triangle

side1 = 2
side2 = 1
side3 = 8

# calculate the semi perimeter in Python
peri = (side1 + side2 + side3) / 2

# calculate the area of a triangle
areaTriangle = (peri*(peri-side1)*(peri-side1)*(peri-side1)) ** 0.5

print('The area of the triangle is %0.2f' %areaTriangle)

Output

The area of the triangle is 15.36