Python Program to Calculate the Area of a Triangle


Levels of difficulty: / perform operation:

Source Code:


# Python Program to find the area of triangle
# Three sides of the triangle a, b and c are provided by the user

a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: '))

# calculate the semi-perimeter
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)

Output:


Enter first side: 5
Enter second side: 6
Enter third side: 7
The area of the triangle is 14.70


Explanation

In this program, we asked users to enter the length of three sides of a triangle. We used the Heron’s Formula to calculate the semi-perimeter and hence the area of the triangle.






Quantitative Aptitude
Reasoning
Programming
Interview