Python Program to Calculate the Area of a Triangle

Python Program to Calculate the Area of a Triangle: In this program, we will learn about python program to calculate the area of a triangle.

If X, Y and Z are three sides of a triangle. Then,

s = (X+Y+Z)/2
area = √(s(s-X)(s-Y)(s-Z))

Python Program to Calculate the Area of a Triangle

Source code

# Python Program to find the area of triangle

X = 5
Y = 6
Z = 7

# Uncomment below to take inputs from the user
# X = float(input('Enter first side: '))
# Y = float(input('Enter second side: '))
# Z = float(input('Enter third side: '))

# calculate the semi-perimeter
s = (X + Y + Z) / 2

# calculate the area
area = (s*(s-X)*(s-Y)*(s-Z)) ** 0.5
print('The area of the triangle is %0.2f' %area)

Output of program