Python program to find the area of a triangle

This article shows that python program to find a area of triangle.

Mathematical formula to find the area of triangle:

Area of a triangle = (s*(s-x)*(s-y)*(s-z))1/2

Here s is the semi-perimeter and x, y and z are three sides of the triangle.

Semi-Perimeter of a triangle = (x + y + z) / 2

Python Program to do arithmetical calculation.


    # Three sides of the triangle is x, y and z:  
    x = float(input('Enter first side: '))  
    y = float(input('Enter second side: '))  
    z = float(input('Enter third side: '))  
    # calculate the semi-perimeter  
    s = (x + y + z) / 2  
    # calculate the area  
    area = (s*(s-x)*(s-y)*(s-z)) ** 0.5  
    print('The area of the triangle is %0.3f' %area)   


1. Here ** is exponent operator for calculating exponent of any number. This operator works for all positive real numbers. But for negative or complex numbers, it not works.

2. %0.3f floating point specifies at least 0 wide and 3 numbers after decimal. If you use %0.4f then it will give 4 numbers after decimal.


See this example to clarify the second point of the Note:

Note: If you interested lo learn Python through web, You can click here


Hi guys, I can hope that you can know that how to write a Python program to find the area of a triangle. If you like this post as well as know something new so share this article in your social media accounts. If you have any doubt related to this post then you ask in comment section.

Leave a Comment

WC Captcha three + six =