Skip to content
Home » Python Program to Find Area of Triangle Given Three Sides

Python Program to Find Area of Triangle Given Three Sides

Learn about Python Program to Find Area of Triangle Given Three Sides in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Python Program to Find Area of Triangle Given Three Sides

# python program to find the area of the triangle

# sides inputs
a = float(input('Enter the first side of the triangle: '))
b = float(input('Enter the second side of the triangle: '))
c = float(input('Enter the third side of the triangle: '))

#checking conditions
# sum of two sides must be smaller than the third side.  
if (a < 0 or b < 0 or c < 0 or (a+b <= c) or (a+c <=b) or (b+c <=a) ):
    print('Not a valid triangle')

else:
    s = (a + b + c) / 2
    area = (s * (s - a) * (s - b) * (s - c)) ** 0.5
    print('Area of triangle = %0.2f' %area)

Output:

Enter the first side of the triangle: 3
Enter the second side of the triangle: 4
Enter the third side of the triangle: 5
Area of triangle = 6.00

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Code : Python Program to Find Area of Triangle