Python Program to Calculate the Area of Triangle


This content was proof-read by Grammarly. You can Try Grammary for FREE

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.


Are you a .NET Developer planning to integrate GraphQL for .NET in your Application? Check out this book BUY & DOWNLOAD GRAPHQL.NET COOKBOOK
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

%d bloggers like this: