Worldscope

Write a program to find the Surface Area of the Pentagonal Prism

Palavras-chave:

Publicado em: 05/08/2025

Calculating the Surface Area of a Pentagonal Prism

This article explains how to calculate the surface area of a pentagonal prism using a simple program. A pentagonal prism is a three-dimensional geometric shape with two pentagonal bases and five rectangular sides. The program will take the side length of the pentagon and the height of the prism as input and output the surface area.

Fundamental Concepts / Prerequisites

Before diving into the code, it's important to understand the formula for calculating the surface area of a pentagonal prism. The surface area (SA) is calculated as follows:

SA = (5/2) * a2 * tan(54°) + 5 * a * h

Where:

  • `a` is the side length of the pentagon
  • `h` is the height of the prism

You should also have a basic understanding of programming concepts like variables, input/output, and mathematical functions.

Implementation in Python


import math

def pentagonal_prism_surface_area(side_length, height):
  """
  Calculates the surface area of a pentagonal prism.

  Args:
    side_length: The length of a side of the pentagonal base.
    height: The height of the prism.

  Returns:
    The surface area of the pentagonal prism.
  """

  base_area = (5/2) * side_length**2 * math.tan(math.radians(54))  # Convert 54 degrees to radians for math.tan
  lateral_area = 5 * side_length * height
  surface_area = 2 * base_area + lateral_area  # Two bases

  return surface_area

# Get input from the user
side_length = float(input("Enter the side length of the pentagon: "))
height = float(input("Enter the height of the prism: "))

# Calculate the surface area
surface_area = pentagonal_prism_surface_area(side_length, height)

# Print the result
print("The surface area of the pentagonal prism is:", surface_area)

Code Explanation

The code starts by importing the `math` module, which provides access to mathematical functions like `tan` and `radians`.

The `pentagonal_prism_surface_area` function takes two arguments: `side_length` and `height`. It calculates the base area using the formula (5/2) * a2 * tan(54°). Note that the angle 54 degrees is converted to radians before passing it to the `math.tan` function.

The lateral area (the area of the five rectangular sides) is calculated as 5 * a * h.

Finally, the total surface area is calculated as 2 * base_area + lateral_area, since there are two pentagonal bases.

The code then prompts the user to enter the side length and height, converts the input to floating-point numbers, calls the `pentagonal_prism_surface_area` function, and prints the result.

Complexity Analysis

Time Complexity: The time complexity of the `pentagonal_prism_surface_area` function is O(1) because it performs a fixed number of arithmetic operations regardless of the input values. The input and output operations are also O(1). Therefore, the overall time complexity is O(1).

Space Complexity: The space complexity is also O(1) because the function uses a fixed number of variables to store the side length, height, base area, lateral area, and surface area. The space used does not depend on the input size.

Alternative Approaches

Instead of using the `math.tan` function, you could pre-calculate the value of `tan(54°)` and use that constant value directly in the formula. This would avoid the need to import the `math` module. However, it would make the code slightly less readable since the origin of the constant value would not be immediately clear. Another approach might involve using a library specifically designed for geometric calculations if dealing with many shapes beyond this one prism.

Conclusion

This article provided a step-by-step guide to calculating the surface area of a pentagonal prism using a Python program. The program takes the side length of the pentagon and the height of the prism as input and returns the surface area based on the standard geometric formula. The solution has a constant time and space complexity, making it efficient for practical use. We also discussed alternative approaches and their respective trade-offs.