Python program to find area of a triangle ( given all sides )

Hello everybody, welcome back! Here we learn how to find the area of a triangle when all the 3 sides of it are given.

First, we calculate semi-perimeter s as sum of all sides divided by 2 then calculate the area using the formula (s*(s-a)*(s-b)*(s-c)) ** 0.5

Program on Github

Formulae :

Semi-perimeter  : s = (a + b + c) / 2

Area = (s*(s-a)*(s-b)*(s-c)) ** 0.5

Task :

To find the area of a triangle when all 3 sides of a triangle are given.

Approach :

  • Read three sides(a, b, c) of a triangle using input()orraw_input().
  • We calculate the semi-perimeter s as sum of all three sides divided by 2. s = ( a + b + c ) / 2
  • After calculating semi-perimeter, we calculate is area as square root of (s*(s-a)*(s-b)*(s-c))
  • For finding square root we can use a function called sqrt from math module or by using exponential operation, we discussed about both sqrt function and using exponential operation
  • We use exponential operation here to calculate area. area =  (s*(s-a)*(s-b)*(s-c)) ** 0.5
  • Finally, print the result.

Program on Github

Area of Triangle – Code Visualization

Program :

Output :

Area of a triangle when 3 sides are given - programminginpython.com
Area of a triangle – programminginpython.com
Area of a triangle when 3 sides are given - programminginpython.com
Area of a triangle – programminginpython.com

Program on Github

Leave a Reply