{"id":18865,"date":"2021-08-26T10:37:39","date_gmt":"2021-08-26T05:07:39","guid":{"rendered":"https:\/\/python-programs.com\/?p=18865"},"modified":"2021-11-22T18:37:19","modified_gmt":"2021-11-22T13:07:19","slug":"python-program-to-compute-the-area-and-perimeter-of-octagon","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-compute-the-area-and-perimeter-of-octagon\/","title":{"rendered":"Python Program to Compute the Area and Perimeter of Octagon"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Compute the Area and Perimeter of Heptagon<\/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 Octagon:<\/strong><\/p>\n An octagon is a polygon with eight sides. It has eight different angles.<\/p>\n Octagon = octa + gon, where octa is the number eight and gon is the number of sides.<\/p>\n In an octagon, there are 20 diagonals.<\/p>\n Formula to calculate the area of an Octagon:<\/b><\/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 Octagon’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 Heptagon 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 Octagon's side length = 6<\/pre>\n
The Octagon's Area with given side length { 6 } = 173.82337649086284\r\nThe Octagon's Perimeter with the given side length { 6 } = 48<\/pre>\n
Given The Octagon's side length = 12.5<\/pre>\n
The Octagon's Area with given side length { 12.5 } = 754.4417382415921\r\nThe Octagon's Perimeter with the given side length { 12.5 } = 100.0<\/pre>\n<\/div>\n
Program to Compute the Area and Perimeter of Octagon<\/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 Octagon's side length as static input and store it in a variable.\r\nside_len = 6\r\n# Calculate the area of the given Octagon using the above given mathematical formula\r\n# and sqrt(), math.pow() functions.\r\n# Store it in another variable.\r\noctgn_area = (2*(1+math.sqrt(2))*math.pow(side_len, 2))\r\n# Calculate the perimeter of the given Octagon using the above given mathematical formula.\r\n# Store it in another variable.\r\noctgn_perimetr = (8*side_len)\r\n# Print the Octagon's area with the given side length.\r\nprint(\r\n \"The Octagon's Area with given side length {\", side_len, \"} =\", octgn_area)\r\n# Print the Octagon's perimeter with the given side length.\r\nprint(\r\n \"The Octagon's Perimeter with the given side length {\", side_len, \"} =\", octgn_perimetr)\r\n<\/pre>\n
The Octagon's Area with given side length { 6 } = 173.82337649086284\r\nThe Octagon's Perimeter with the given side length { 6 } = 48<\/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 Octagon'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 Octagon using the above given mathematical formula\r\n# and sqrt(), math.pow() functions.\r\n# Store it in another variable.\r\noctgn_area = (2*(1+math.sqrt(2))*math.pow(side_len, 2))\r\n# Calculate the perimeter of the given Octagon using the above given mathematical formula.\r\n# Store it in another variable.\r\noctgn_perimetr = (8*side_len)\r\n# Print the Octagon's area with the given side length.\r\nprint(\r\n \"The Octagon's Area with given side length {\", side_len, \"} =\", octgn_area)\r\n# Print the Octagon's perimeter with the given side length.\r\nprint(\r\n \"The Octagon's Perimeter with the given side length {\", side_len, \"} =\", octgn_perimetr)\r\n<\/pre>\n
Enter some random number = 12.5\r\nThe Octagon's Area with given side length { 12.5 } = 754.4417382415921\r\nThe Octagon's Perimeter with the given side length { 12.5 } = 100.0<\/pre>\n
\n