# Python Program to Compute the Area and Perimeter of Heptagon

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 math module.

Heptagon:

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.

Formula to calculate the area of a Heptagon:

In which  a is the Heptagon’s side length

Formula to calculate the perimeter of a Heptagon:

Perimeter = 7a

Given the Heptagon’s side length and the task is to calculate the area and perimeter of the given Heptagon.

Examples:

Example1:

Input:

Given The Heptagon's side length = 8

Output:

The Heptagon's Area with given side length { 8 } = 232.576
The Heptagon's Perimeter with the given side length { 8 } = 56

Example2:

Input:

Given The Heptagon's side length = 15

Output:

The Heptagon's Area with given side length { 15 } = 817.65
The Heptagon's Perimeter with the given side length { 15 } = 105

## Program to Compute the Area and Perimeter of Heptagon

Below are the ways to Calculate the area and perimeter of a heptagon with the given heptagon’s side length:

### Method #1: Using Mathematical Formula (Static Input)

Approach:

• Import the math module using the import keyword.
• Give the heptagon’s side length as static input and store it in a variable.
• Calculate the area of the given heptagon using the above given mathematical formula and pow() function.
• Store it in another variable.
• Calculate the perimeter of the given heptagon using the above given mathematical formula.
• Store it in another variable.
• Print the heptagon’s area with the given side length.
• Print the heptagon’s perimeter with the given side length.
• The Exit of the program.

Below is the implementation:

# Import the math module using the import keyword.
import math
# Give the heptagon's side length as static input and store it in a variable.
side_len = 8
# Calculate the area of the given heptagon using the above given mathematical formula
# and pow() function.
# Store it in another variable.
heptagn_area = 3.634*pow(side_len, 2)
# Calculate the perimeter of the given heptagon using the above given mathematical formula.
# Store it in another variable.
heptagn_perimetr = (7*side_len)
# Print the heptagon's area with the given side length.
print(
"The Heptagon's Area with given side length {", side_len, "} =", heptagn_area)
# Print the heptagon's perimeter with the given side length.
print(
"The Heptagon's Perimeter with the given side length {", side_len, "} =", heptagn_perimetr)


Output:

The Heptagon's Area with given side length { 8 } = 232.576
The Heptagon's Perimeter with the given side length { 8 } = 56

### Method #2: Using Mathematical Formula (User Input)

Approach:

• Import the math module using the import keyword.
• Give the Heptagon’s side length as user input using float(input()) function and store it in a variable.
• Calculate the area of the given heptagon using the above given mathematical formula and pow() function.
• Store it in another variable.
• Calculate the perimeter of the given heptagon using the above given mathematical formula.
• Store it in another variable.
• Print the heptagon’s area with the given side length.
• Print the heptagon’s perimeter with the given side length.
• The Exit of the program.

Below is the implementation:

# Import the math module using the import keyword.
import math
# Give the Heptagon's side length as user input using float(input()) function and
# store it in a variable.
side_len = float(input("Enter some random variable = "))
# Calculate the area of the given heptagon using the above given mathematical formula
# and pow() function.
# Store it in another variable.
heptagn_area = 3.634*pow(side_len, 2)
# Calculate the perimeter of the given heptagon using the above given mathematical formula.
# Store it in another variable.
heptagn_perimetr = (7*side_len)
# Print the heptagon's area with the given side length.
print(
"The Heptagon's Area with given side length {", side_len, "} =", heptagn_area)
# Print the heptagon's perimeter with the given side length.
print(
"The Heptagon's Perimeter with the given side length {", side_len, "} =", heptagn_perimetr)


Output:

Enter some random variable = 15
The Heptagon's Area with given side length { 15.0 } = 817.65
The Heptagon's Perimeter with the given side length { 15.0 } = 105.0

Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.