;

Python Program to Calculate the Area of a Triangle


Tutorialsrack 22/04/2020 Python

In this Python program, we will learn how to calculate the area of a triangle. In this program, we are using Heron’s formula to calculate the area of a triangle. Heron’s formula is one of the most important concepts used to find the area of a triangle when all the sides are known.

 Suppose, a triangle ABC, whose sides are a, b and c, respectively. Thus, the area of a triangle can be given by;

s = (a+b+c)/2

area = √(s(s-a)*(s-b)*(s-c))

Where “s” is semi-perimeter = (a+b+c) / 2  and a, b, c are the three sides of the triangle.

Here is the source code of the program to take the input from the user and calculate the area of the triangle and display the output using a print() function

Python Program to Calculate the Area of a Triangle
# Python Program to find the Area Of a Triangle
 
# Take the Input From the User
a = float(input("Enter the First side of a Triangle: "))
b = float(input("Enter the Second side of a Triangle: "))
c = float(input("Enter the Third side of a Triangle: "))
 
# calculate the Perimeter
Perimeter = a + b + c
 
# calculate the semi-perimeter
s = (a + b + c) / 2
 
# calculate the area
Area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
 
print("\nThe Perimeter of Traiangle = %.2f" %Perimeter);
print("The Semi Perimeter of Traiangle = %.2f" %s);
print("The Area of a Triangle is %0.2f" %Area)
Output

Enter the First side of a Triangle: 5

Enter the Second side of a Triangle: 6

Enter the Third side of a Triangle: 7


Related Posts



Comments

Recent Posts
Tags