Python Program to find area of pentagon

Program

apothem = int(input("Enter the apothem:\t"));
side = int(input("Enter the length of side:\t"));
area_num = (5 * side * apothem);
area = area_num / 2;
print("Area of pentagon:", area);

This program calculates the area of a regular pentagon using the formula:
[
\text{Area} = \frac{5 \times \text{Side} \times \text{Apothem}}{2} ]
where:

  • Side = Length of one side of the pentagon
  • Apothem = Perpendicular distance from the center to the middle of a side
apothem = int(input("Enter the apothem:\t"))
side = int(input("Enter the length of side:\t"))
  • The user inputs the apothem and side length of the pentagon.
  • input() takes user input as a string, and int() converts it to an integer.
area_num = (5 * side * apothem)
area = area_num / 2
  • First, computes the numerator of the formula:
    [
    5 \times \text{Side} \times \text{Apothem} ]
  • Then, divides by 2 to get the final area.
print("Area of pentagon:", area)
  • Displays the computed area.

Case 1: Side = 10, Apothem = 8

User Input:

Enter the apothem: 8
Enter the length of side: 10

Calculation:
[
\frac{5 \times 10 \times 8}{2} = \frac{400}{2} = 200 ] Output:

Area of pentagon: 200.0

Case 2: Side = 7, Apothem = 6

User Input:

Enter the apothem: 6
Enter the length of side: 7

Calculation:
[
\frac{5 \times 7 \times 6}{2} = \frac{210}{2} = 105 ] Output:

Area of pentagon: 105.0

Key Takeaways:

  1. Uses the mathematical formula for the area of a pentagon.
  2. Accepts user input for side length and apothem.
  3. Computes area step by step and prints the result.

Output

$ python3 area_of_pentagon.py 
Enter the apothem:		8
Enter the length of side:	6
Area of pentagon: 120.0