Programming Examples
Python Program to Calculate the Area of a Triangle
Write a Python program to accept 3 sides of triangle and find the area of triangle.
s = (a+b+c)/2
area = √(s(s-a)*(s-b)*(s-c))
Solution
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: 4
Enter second side: 5
Enter third side: 6
The area of the triangle is 9.92