This is a Python Program to find the area of a triangle given all three sides.
The program takes three sides of a triangle and prints the area formed by all three sides.
1. Take in all the three sides of the triangle and store it in three separate variables.
2. Then using the Heron’s formula, compute the area of the triangle.
3. Print the area of the triangle.
4. Exit.
Here is source code of the Python Program to find the area of a triangle given all three sides. The program output is also shown below.
import math a=int(input("Enter first side: ")) b=int(input("Enter second side: ")) c=int(input("Enter third side: ")) s=(a+b+c)/2 area=math.sqrt(s*(s-a)*(s-b)*(s-c)) print("Area of the triangle is: ",round(area,2))
1. User must enter all three numbers and store it in separate variables.
2. First the value of s is found out which is equal to (a+b+c)/2
3. Then the Heron’s formula is applied to determine the area of the triangle formed by all three sides.
4. Then the area of the triangle is printed.
Case 1: Enter first side: 15 Enter second side: 9 Enter third side: 7 Area of the triangle is: 20.69 Case 2: Enter first side: 5 Enter second side: 6 Enter third side: 7 Area of the triangle is: 14.7
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Check Python Books
- Apply for Python Internship
- Apply for Programming Internship
- Check Information Technology Books
- Practice Programming MCQs