Calculate the Area of a Triangle - Python Last Updated : 29 Apr, 2025 Comments Improve Suggest changes Like Article Like Report A triangle is a closed-shaped two-dimensional polygon having three sides and three corners. The corners are called vertices and the sides are called edges. In this article, we will see how we can calculate the area of a triangle in Python.Using Heron's FormulaWhen the lengths of all three sides of the triangle are known, you can use Heron's Formula. The formula is:A = \sqrt{s(s - a)(s - b)(s - c)}where:a,b,c are the lengths of the sides of the triangle.s is the semi-perimeter, calculated as:s = \frac{a + b + c}{2} Python a = 7 b = 8 c = 9 s = (a + b + c) / 2 res = (s * (s - a) * (s - b) * (s - c)) ** 0.5 print(res) Output26.832815729997478 Using Base and HeightFor a right-angled triangle or when the base and height are given, you can calculate the area using the formula:\text{Area} = \frac{1}{2} \times \text{base} \times \text{height} Python b = 8 h = 9 res = 0.5 * b * h print(res) Output36.0 Using coordinates of verticesIf the coordinates of the three vertices of the triangle are known, you can calculate the area using the Shoelace Theorem (also known as the Surveyor's Formula):surveyor's formulaWhere (x1y1),(x2,y2) and (x3,y3) are the coordinates of the three vertices. Python x1, y1 = 0, 0 x2, y2 = 5, 0 x3, y3 = 5, 7 res = 0.5 * abs(x1*y2 + x2*y3 + x3*y1 - y1*x2 - y2*x3 - y3*x1) print(res) Output17.5 Comment More infoAdvertise with us Next Article Calculate the Area of a Triangle - Python R rudek5bw7 Follow Improve Article Tags : Python Python Programs python-basics Practice Tags : python Similar Reads Python Program for Program to calculate area of a Tetrahedron A Tetrahedron is simply a pyramid with a triangular base. It is a solid object with four triangular faces, three on the sides or lateral faces, one on the bottom or the base and four vertices or corners. If the faces are all congruent equilateral triangles, then the tetrahedron is called regular. Th 2 min read Calculate Surface Area and Volume of a Cylinder in Python Cylinders are common three-dimensional geometric shapes that can be found in various objects around us, from soda cans to industrial pipes. Understanding how to calculate their surface area and volume is essential in many fields, including engineering, physics, and computer science. In this article, 3 min read Python Program to Find Area of Rectangle The task of calculating the Area of a Rectangle in Python involves taking the length and width as input, applying the mathematical formula for the area of a rectangle, and displaying the result.Area of Rectangle Formula :Area = Width * HeightWhere:Length is the longer side of the rectangle.Width is 2 min read Python Program to Check if right triangle possible from given area and hypotenuse A triangle is said to as having "right angles" if one of its angles is a right angle. The "legs" of a triangle are the two sides that cross over one another to make a right angle. The "hypotenuse" side of a triangle is the side that faces the right angle formed by the triangle. In this article, we'l 6 min read Python program to print the Inverted heart pattern Let us see how to print an inverted heart pattern in Python. Example: Input: 11 Output: * *** ***** ******* ********* *********** ************* *************** ***************** ******************* ********************* ********* ******** ******* ****** ***** **** Input: 15 Output: * *** ***** ***** 2 min read Like