{"id":7330,"date":"2021-09-30T11:30:56","date_gmt":"2021-09-30T06:00:56","guid":{"rendered":"https:\/\/python-programs.com\/?p=7330"},"modified":"2021-11-22T18:35:27","modified_gmt":"2021-11-22T13:05:27","slug":"python-program-to-calculate-the-area-semi-perimeter-and-perimeter-of-a-triangle","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-the-area-semi-perimeter-and-perimeter-of-a-triangle\/","title":{"rendered":"Python Program to Calculate the Area, Semi Perimeter and Perimeter of a Triangle"},"content":{"rendered":"
Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners<\/a> tutorial.<\/p>\n With an example, learn how to construct a Python program to find the Area of a Triangle, Perimeter of a Triangle, and Semi-Perimeter of a Triangle. Let’s look at the definitions and mathematics underlying Perimeter and Area of a Triangle before diving into the Python program to find Area of a Triangle.<\/p>\n Area of Triangle:<\/strong><\/p>\n If we know the lengths of the three sides of a triangle, we can use Heron’s Formula to compute the area of the triangle.<\/p>\n Triangle Area = \u221a((s*(s-a)*(s-b)*(s-c)))<\/p><\/blockquote>\n Where<\/p>\n (Here s = semi perimeter and a, b, c are the three sides of a given_triangle)<\/p>\n Example 1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Let us calculate the area, semi perimeter and perimeter of Triangle in Python:<\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n We can calculate semi perimeter using the formula<\/p>\n s=(a+b+c)\/2 where a , b ,c are sides of the triangle<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n We can calculate perimeter using the formula<\/p>\n perimeter=(a+b+c) where a , b ,c are sides of the triangle<\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n When three sides are specified in this program, the area of the triangle will be determined using Heron’s formula.<\/p>\n If you need to calculate the area of a triangle based on user input, you can utilize the input() function.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Related Programs<\/strong>:<\/p>\n Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners tutorial. With an example, learn how to construct a Python program to find the Area of a Triangle, Perimeter of a Triangle, and Semi-Perimeter of a Triangle. Let’s look at the definitions and mathematics underlying …<\/p>\ns = (a + b + c )\/ 2<\/pre>\n
Perimeter of a Triangle = a + b + c<\/pre>\n
Examples:<\/h2>\n
a = 24\r\nb = 12\r\nc = 22<\/pre>\n
The semiperimeter of the triangle with the sides 24 12 22 = 29.0\r\nThe perimeter of the triangle with the sides 24 12 22 = 58\r\nThe area of the triangle with the sides 24 12 22 =131.358<\/pre>\n
a = 5.6\r\nb = 2.7\r\nc = 7.9<\/pre>\n
The semiperimeter of the triangle with the sides 5.6 2.7 7.9 =8.100\r\nThe perimeter of the triangle with the sides 5.6 2.7 7.9 =16.200\r\nThe area of the triangle with the sides 5.6 2.7 7.9 =4.677<\/pre>\n
Program to Calculate the Area, Semi Perimeter and Perimeter of a Triangle<\/h2>\n
\n
1)Calculating Semi Perimeter of the given triangle<\/h3>\n
# given sides of the triangle\r\na = 24\r\nb = 12\r\nc = 22\r\n\r\n# calculating the semi perimeter of the given triangle by using the formula\r\nsemi_perimeter = (a + b + c) \/ 2\r\n# print semi_perimeter\r\nprint(\"The semiperimeter of the triangle with the sides\", a, b, c, \"=\", semi_perimeter)\r\n<\/pre>\n
The semiperimeter of the triangle with the sides 24 12 22 = 29.0<\/pre>\n
2)Calculating Perimeter of the given triangle<\/h3>\n
# given sides of the triangle\r\na = 24\r\nb = 12\r\nc = 22\r\n\r\n# calculating the perimeter of the given triangle by using the formula\r\nperimetr = (a + b + c)\r\n# print perimeter\r\nprint(\"The perimeter of the triangle with the sides\", a, b, c, \"=\", perimetr)\r\n<\/pre>\n
The perimeter of the triangle with the sides 24 12 22 = 58<\/pre>\n
3)Calculating Area of Triangle<\/h3>\n
\n
# given sides of the triangle\r\na = 24\r\nb = 12\r\nc = 22\r\n\r\n# calculating the semiperimeter of the given triangle by using the formula\r\ns = (a + b + c)\/2\r\n# calculating area of triangle with given sides\r\ntriangleArea = (s*(s-a)*(s-b)*(s-c)) ** 0.5\r\n# print the area of thee triangle\r\nprint(\"The area of the triangle with the sides\",\r\n a, b, c, \"=%0.3f\" % triangleArea)\r\n<\/pre>\n
The area of the triangle with the sides 24 12 22 =131.358<\/pre>\n
\n