{"id":22752,"date":"2021-09-27T15:43:17","date_gmt":"2021-09-27T10:13:17","guid":{"rendered":"https:\/\/python-programs.com\/?p=22752"},"modified":"2021-11-22T18:35:37","modified_gmt":"2021-11-22T13:05:37","slug":"python-program-to-calculate-area-and-perimeter-of-equilateral-triangle","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-area-and-perimeter-of-equilateral-triangle\/","title":{"rendered":"Python Program to Calculate Area and Perimeter of Equilateral Triangle"},"content":{"rendered":"
In the previous article, we have discussed Python Program for Maximum Number of 2\u00d72 Squares That Can be Fit Inside a Right Isosceles Triangle<\/a> Equilateral triangle:<\/strong><\/p>\n An equilateral triangle is one with equal sides and angles on all three sides. The internal angles of an equilateral triangle are all 60 degrees.<\/p>\n Formulas:<\/strong><\/p>\n Let ‘a’<\/strong> be the side length of the equilateral triangle.<\/p>\n Area = (sqrt(3)\/4) * a * a<\/p>\n Perimeter = 3*a<\/p><\/blockquote>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to calculate the area and perimeter of the equilateral triangle with the given side length:<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n If you wanna write simple python programs as a part of your coding practice refer to numerous Simple Python Program Examples<\/a> existing and learn the approach used.<\/p>\n In the previous article, we have discussed Python Program for Maximum Number of 2\u00d72 Squares That Can be Fit Inside a Right Isosceles Triangle Given the side length of the equilateral triangle and the task is to calculate the area and perimeter of the equilateral triangle with the given side length. Equilateral triangle: An equilateral …<\/p>\n
\nGiven the side length of the equilateral triangle and the task is to calculate the area and perimeter of the equilateral triangle with the given side length.<\/p>\nGiven side length = 8<\/pre>\n
The Area of Equilateral Triangle with the given side length [ 8 ] = 27.712813\r\nThe Perimeter of Equilateral Triangle with the given side length [ 8 ] = 24.000000<\/pre>\n
Given side length = 5<\/pre>\n
The Area of Equilateral Triangle with the given side length [ 5 ] = 10.825318\r\nThe Perimeter of Equilateral Triangle with the given side length [ 5 ] = 15.000000<\/pre>\n
Program to Calculate Area and Perimeter of Equilateral Triangle in Python<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Import the math module using the import keyword.\r\nfrom math import *\r\n# Give the side length as static input and store it in a variable.\r\ngvn_side_len = 8\r\n# Calculate the area of the equilateral triangle using the above mathematical formula\r\n# given and store it in another variable.\r\nrslt_area = (sqrt(3) \/ 4) * gvn_side_len * gvn_side_len\r\n# Calculate the perimeter of the equilateral triangle using the above mathematical\r\n# formula given and store it in another variable.\r\nrslt_perimetr = 3 * gvn_side_len\r\n# Print the area of the equilateral triangle for the given side length.\r\nprint(\r\n \"The Area of Equilateral Triangle with the given side length [\", gvn_side_len, \"] = % f\" % rslt_area)\r\n# Print the perimeter of the equilateral triangle for the given side length.\r\nprint(\r\n \"The Perimeter of Equilateral Triangle with the given side length [\", gvn_side_len, \"] = % f\" % rslt_perimetr)\r\n<\/pre>\n
The Area of Equilateral Triangle with the given side length [ 8 ] = 27.712813\r\nThe Perimeter of Equilateral Triangle with the given side length [ 8 ] = 24.000000<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Import the math module using the import keyword.\r\nfrom math import *\r\n# Give the side length as user input using the float(input()) function and\r\n# store it in a variable.\r\ngvn_side_len = float(input(\"Enter some random number = \"))\r\n# Calculate the area of the equilateral triangle using the above mathematical formula\r\n# given and store it in another variable.\r\nrslt_area = (sqrt(3) \/ 4) * gvn_side_len * gvn_side_len\r\n# Calculate the perimeter of the equilateral triangle using the above mathematical\r\n# formula given and store it in another variable.\r\nrslt_perimetr = 3 * gvn_side_len\r\n# Print the area of the equilateral triangle for the given side length.\r\nprint(\r\n \"The Area of Equilateral Triangle with the given side length [\", gvn_side_len, \"] = % f\" % rslt_area)\r\n# Print the perimeter of the equilateral triangle for the given side length.\r\nprint(\r\n \"The Perimeter of Equilateral Triangle with the given side length [\", gvn_side_len, \"] = % f\" % rslt_perimetr)\r\n<\/pre>\n
Enter some random number = 5\r\nThe Area of Equilateral Triangle with the given side length [ 5.0 ] = 10.825318\r\nThe Perimeter of Equilateral Triangle with the given side length [ 5.0 ] = 15.000000<\/pre>\n
\n