Python | Program to Find Area of Triangle

Mathematically, area of triangle is defined as Region occupied by three lines which are connected with each other consequently. Area of a triangle can also be defined as under root of (s * (s – a) * (s – b) * (s – c)) where s is parameter of triangle while a, b, c are three sides. This way of calculating area of a triangle is called Heron’s Formula and it’s used for calculating if in case length of sides of triangle is given.
Quite Simple, let’s see how this mathematical logic can be moulded as some Python Algorithm.

Table of Contents

Area of Triangle

  1. Ask user for three sides of triangle as variables a, b, c
  2. Calculate perimeter of triangle as s = (a + b + c) / 2
  3. Multiply perimeter of triangle with number 0.5 which will return Area of Triangle

Python Code

# Three sides of the triangle is a, b and c:

a = float(input('Enter first side: '))  
b = float(input('Enter second side: '))  
c = float(input('Enter third side: '))  
# calculate the semi-perimeter of triangle 
s = (a + b + c) / 2  
# calculate the area  
area_of_triangle = (s*(s-a)*(s-b)*(s-c)) ** 0.5  

print('The area of the triangle is =>', area_of_triangle)

Output of Above Code

Enter first side: 3
Enter second side: 4
Enter third side: 5
The area of the triangle is => 6.0


Hi, there I'm founder of ComputerScienceHub(Started this to bring useful Computer Science information just at one place). Personally I've been doing JavaScript, Python development since 2015(Been long) - Worked upon couple of Web Development Projects, Did some Data Science stuff using Python. Nowadays primarily I work as Freelance JavaScript Developer(Web Developer) and on side-by-side managing team of Computer Science specialists at

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts