fastread homefastrread library fastread menu

Python : Calculate the Area of a Triangle

Tutorial by:Rizwan Abdullah      Date: 2016-06-16 00:42:45

❰ Previous Next ❱

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)


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

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.

❰ Previous Next ❱


Submit Your Thought, Tutorial, Articls etc.

Submit Your Information India's Number one online promotion website