{"id":18859,"date":"2021-08-26T10:37:46","date_gmt":"2021-08-26T05:07:46","guid":{"rendered":"https:\/\/python-programs.com\/?p=18859"},"modified":"2021-11-22T18:37:19","modified_gmt":"2021-11-22T13:07:19","slug":"python-program-to-compute-the-area-and-perimeter-of-pentagon","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-compute-the-area-and-perimeter-of-pentagon\/","title":{"rendered":"Python Program to Compute the Area and Perimeter of Pentagon"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Compute the Area and Perimeter of Octagon<\/a> A pentagon (from the Greek v Pente and gonia, which mean five and angle) is any five-sided polygon or 5-gon. A simple pentagon’s internal angles add up to 540\u00b0.<\/p>\n A pentagon can be simple or complex, and it can be self-intersecting. A pentagram is a self-intersecting regular pentagon (or a star pentagon).<\/p>\n Formula to calculate the area of a pentagon:<\/b><\/p>\n <\/a><\/p>\n Formula to calculate the perimeter of a pentagon:<\/b><\/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 a pentagon with the given Pentagon’s 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 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 In the previous article, we have discussed Python Program to Compute the Area and Perimeter of Octagon Pentagon: A pentagon (from the Greek v Pente and gonia, which mean five and angle) is any five-sided polygon or 5-gon. A simple pentagon’s internal angles add up to 540\u00b0. A pentagon can be simple or complex, and …<\/p>\n
\nPentagon:<\/strong><\/p>\nGiven The Pentagon's side length = 10<\/pre>\n
The Pentagon's area with given side length { 10 } = 172.0477400588967\r\nThe Pentagon's Perimeter with given side length { 10 } = 50<\/pre>\n
Given The Pentagon's side length = 5.5<\/pre>\n
The Pentagon's area with given side length { 5.5 } = 52.04444136781625\r\nThe Pentagon's Perimeter with given side length { 5.5 } = 27.5<\/pre>\n<\/div>\n
Program to Compute the Area and Perimeter of Pentagon in Python<\/h2>\n
\n
Method #1: Using Mathematical Formula (Static Input)<\/h3>\n
\n
# Import the math module using the import keyword.\r\nimport math\r\n# Give the Pentagon's side length as static input and store it in a variable.\r\nside_len = 10\r\n# Calculate the area of the given pentagon using the above given mathematical formula and\r\n# math.sqrt() function.\r\n# Store it in another variable.\r\npentgn_area = (math.sqrt(5*(5+2*math.sqrt(5)))*pow(side_len, 2))\/4.0\r\n# Calculate the perimeter of the given pentagon using the above given mathematical formula.\r\n# Store it in another variable.\r\npentgn_perimtr = (5*side_len)\r\n# Print the Pentagon's area with the given side length.\r\nprint(\r\n \"The Pentagon's area with given side length {\", side_len, \"} =\", pentgn_area)\r\n# Print the Pentagon's perimeter with the given side length.\r\nprint(\r\n \"The Pentagon's Perimeter with given side length {\", side_len, \"} =\", pentgn_perimtr)\r\n<\/pre>\n
The Pentagon's area with given side length { 10 } = 172.0477400588967\r\nThe Pentagon's Perimeter with given side length { 10 } = 50<\/pre>\n
Method #2: Using Mathematical Formula (User Input)<\/h3>\n
\n
# Import the math module using the import keyword.\r\nimport math\r\n# Give the Pentagon's side length as user input using float(input()) function and\r\n# store it in a variable.\r\nside_len = float(input('Enter some random number = '))\r\n# Calculate the area of the given pentagon using the above given mathematical formula and\r\n# math.sqrt() function.\r\n# Store it in another variable.\r\npentgn_area = (math.sqrt(5*(5+2*math.sqrt(5)))*pow(side_len, 2))\/4.0\r\n# Calculate the perimeter of the given pentagon using the above given mathematical formula.\r\n# Store it in another variable.\r\npentgn_perimtr = (5*side_len)\r\n# Print the Pentagon's area with the given side length.\r\nprint(\r\n \"The Pentagon's area with given side length {\", side_len, \"} =\", pentgn_area)\r\n# Print the Pentagon's perimeter with the given side length.\r\nprint(\r\n \"The Pentagon's Perimeter with given side length {\", side_len, \"} =\", pentgn_perimtr)\r\n<\/pre>\n
Enter some random number = 5.5\r\nThe Pentagon's area with given side length { 5.5 } = 52.04444136781625\r\nThe Pentagon's Perimeter with given side length { 5.5 } = 27.5<\/pre>\n
\n