(Python Tutorials for Citizen Data Scientist)
Python Program to Calculate the Area of a Triangle
In this program, you’ll learn to calculate the area of a triangle and display it.
If a, b and c are three sides of a triangle. Then,
s = (a+b+c)/2 area = √(s(s-a)*(s-b)*(s-c))
# Python Program to find the area of triangle a = 5 b = 6 c = 7 # Uncomment below to take inputs from the user # a = float(input('Enter first side: ')) # b = float(input('Enter second side: ')) # c = float(input('Enter third side: ')) # calculate the semi-perimeter s = (a + b + c) / 2 # calculate the area area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 print('The area of the triangle is %0.2f' %area)
The area of the triangle is 14.70
In this program, area of the triangle is calculated when three sides are given using Heron’s formula.
If you need to calculate area of a triangle depending upon the input from the user, input() function can be used.
Python Examples for Beginners: Python Code to Calculate the Area of a Triangle
Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.
Latest end-to-end Learn by Coding Projects (Jupyter Notebooks) in Python and R:
There are 2000+ End-to-End Python & R Notebooks are available to build Professional Portfolio as a Data Scientist and/or Machine Learning Specialist. All Notebooks are only $29.95. We would like to request you to have a look at the website for FREE the end-to-end notebooks, and then decide whether you would like to purchase or not.