Python Calculate the Area of a Triangle with Example
Published on Apr 14, 2022
In this snippet, we will learn to calculate the area of a triangle in Python.
Formula of Area of a Triangle
Let's see the formula:
# find the semi-perimeter of a triangle s = (a+b+c)/2 # formula for the area of a triangle area = (s*(s-a)*(s-b)*(s-c))**0.5
Find Area of a Triangle
Now let's see an example:
a = 4 b = 5 c = 6 # calculate the semi-perimeter of a triangle 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)
The area of the triangle is 9.92
You can also run the program in our IDE.