Python Program to Calculate Area of Triangle


Way 1 – Area of Triangle Using base and height

In [1]:
base = int(input("Please enter base : "))
height = int(input("Please enter height : "))

area = base*height/2

print("Area = ", area)
Please enter base : 5
Please enter height : 6
Area =  15.0

In this approach, we need to have the base and height of the triangle.

Using that base and height, use the formula, i.e. (base*height)/2. And lat last print the area of the triangle.

Way 2 – Area of Triangle Using three sides

In [1]:
side1 = int(input("Please enter side 1 : "))
side2 = int(input("Please enter side 2 : "))
side3 = int(input("Please enter side 3 : "))

s = (side1 + side2 + side3)/2
area = (s*(s-side1)*(s-side2)*(s-side3)) ** 0.5

print("Area = ", area)
Please enter side 1 : 5
Please enter side 2 : 6
Please enter side 3 : 7
Area =  14.696938456699069

In this approach, we need all the sides of the triangle, and ask the user to input all the side of the triangle. Once, we know all the sides of a triangle, we will use the Heron’s formula.

Al last, print the area of the triangle.