Articles

Program to find area of triangle in Python

Program to find area of triangle in Python


In this python programs guide, we will learn to write

  • program to find area of triangle in python

Python program to find area of triangle

The program to find area of triangle in python is as follows :

 

# Owner : TutorialsInhand Author : Devjeet Roy
 
s1 = float(input('Enter first side: '))  
s2 = float(input('Enter second side: '))  
s3 = float(input('Enter third side: '))  
   
s = (s1 + s2 + s3) / 2  
   
area = (s*(s-s1)*(s-s2)*(s-s3)) ** 0.5  
print("The area of the triangle is:", round(area,2))

The output of the python program to find area of triangle is as follows :

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter first side: 30
Enter second side: 40
Enter third side: 20
The area of the triangle is: 290.47

Few important tips about this program:

1. The input data type provided by the input() function is of string data type, we convert that to float data type for mathematical computation.

2. Here, we have used the formula for finding the area of a scalene triangle.

3. We have used the round() function here, to round off the float output upto 2 decimal places.

 

Given below is snapshot of write a python program to find area of triangle:

code to find area of triangle in python

 


Basic Python Programs

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Jan 31,2021  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!