{"id":18862,"date":"2021-08-26T10:37:42","date_gmt":"2021-08-26T05:07:42","guid":{"rendered":"https:\/\/python-programs.com\/?p=18862"},"modified":"2021-11-22T18:37:19","modified_gmt":"2021-11-22T13:07:19","slug":"python-program-to-compute-the-area-and-perimeter-of-heptagon","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-compute-the-area-and-perimeter-of-heptagon\/","title":{"rendered":"Python Program to Compute the Area and Perimeter of Heptagon"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Check if All Characters have Even Frequency<\/a> Python’s math module is a built-in module. By importing this module, we can perform mathematical computations.<\/p>\n Numerous mathematical operations like ceil( ),floor( ),factorial( ),mod( ),value of pi ,…..etc .can be computed with the help of math module.<\/p>\n Heptagon:<\/strong><\/p>\n A heptagon is a seven-sided polygon or 7-gon in geometry. The heptagon is also known as the septagon, which is formed by combining “sept-” (an elision of septua-, a Latin-derived numerical prefix, rather than hepta-, a Greek-derived numerical prefix; both are cognate) and the Greek suffix “-agon” meaning angle.<\/p>\n Formula to calculate the area of a Heptagon:<\/b><\/p>\n <\/p>\n In which\u00a0 a is the Heptagon’s <\/strong>side length<\/p>\n Formula to calculate the perimeter of a Heptagon<\/b>:<\/b><\/strong><\/p>\n Perimeter = 7a<\/p>\n Given the Heptagon’s side length and the task is to calculate the area and perimeter of the given Heptagon.<\/p>\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 a heptagon with the given heptagon’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 Check if All Characters have Even Frequency Math Module : Python’s math module is a built-in module. By importing this module, we can perform mathematical computations. Numerous mathematical operations like ceil( ),floor( ),factorial( ),mod( ),value of pi ,…..etc .can be computed with the help of …<\/p>\n
\nMath Module :<\/strong><\/p>\nGiven The Heptagon's side length = 8<\/pre>\n
The Heptagon's Area with given side length { 8 } = 232.576\r\nThe Heptagon's Perimeter with the given side length { 8 } = 56<\/pre>\n
Given The Heptagon's side length = 15<\/pre>\n
The Heptagon's Area with given side length { 15 } = 817.65\r\nThe Heptagon's Perimeter with the given side length { 15 } = 105<\/pre>\n
Program to Compute the Area and Perimeter of Heptagon<\/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 heptagon's side length as static input and store it in a variable.\r\nside_len = 8\r\n# Calculate the area of the given heptagon using the above given mathematical formula\r\n# and pow() function.\r\n# Store it in another variable.\r\nheptagn_area = 3.634*pow(side_len, 2)\r\n# Calculate the perimeter of the given heptagon using the above given mathematical formula.\r\n# Store it in another variable.\r\nheptagn_perimetr = (7*side_len)\r\n# Print the heptagon's area with the given side length.\r\nprint(\r\n \"The Heptagon's Area with given side length {\", side_len, \"} =\", heptagn_area)\r\n# Print the heptagon's perimeter with the given side length.\r\nprint(\r\n \"The Heptagon's Perimeter with the given side length {\", side_len, \"} =\", heptagn_perimetr)\r\n<\/pre>\n
The Heptagon's Area with given side length { 8 } = 232.576\r\nThe Heptagon's Perimeter with the given side length { 8 } = 56<\/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 Heptagon'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 variable = \"))\r\n# Calculate the area of the given heptagon using the above given mathematical formula\r\n# and pow() function.\r\n# Store it in another variable.\r\nheptagn_area = 3.634*pow(side_len, 2)\r\n# Calculate the perimeter of the given heptagon using the above given mathematical formula.\r\n# Store it in another variable.\r\nheptagn_perimetr = (7*side_len)\r\n# Print the heptagon's area with the given side length.\r\nprint(\r\n \"The Heptagon's Area with given side length {\", side_len, \"} =\", heptagn_area)\r\n# Print the heptagon's perimeter with the given side length.\r\nprint(\r\n \"The Heptagon's Perimeter with the given side length {\", side_len, \"} =\", heptagn_perimetr)\r\n<\/pre>\n
Enter some random variable = 15\r\nThe Heptagon's Area with given side length { 15.0 } = 817.65\r\nThe Heptagon's Perimeter with the given side length { 15.0 } = 105.0<\/pre>\n
\n