Python - Surface Area of Right Pentagonal Pyramid

by matt392 in Circuits > Software

128 Views, 1 Favorites, 0 Comments

Python - Surface Area of Right Pentagonal Pyramid

SurfaceAreRightPentagonalPyramid.jpg
rightpentpyram.jpg
RightPentPyramidFormula.png
Python code is below and attached.
Also made a diagram of how the formula was broken down for coding. PDF attached.
print ("This program will calculate the surface area of a right pentagonal pyramid.  ")

import math

#  Formula for calculating the volume of surface area of a right pentagonal pyramid:
#  SurfaceAreaRightPentagonalPyramid =  ((5/4) * (math.tan(54 degrees) * (BaseEdge**2)) + ((5(BaseEdge/2)) * math.sqrt((height**2)(((BaseEdge*math.tan(54 degrees))/2)**2)))
###########################################

# 1 function: solve for the volume
# math.sqrt(x) - returns square root of "x"
# math.tan(x in radians) - returns tangent of "x" in radians
# Function to solve for the surface area
# Enter the length of the base edge and height
# SurfaceAreaRightPentagonalPyramid =  ((5/4) * (math.tan(54 degrees) * (BaseEdge**2)) + ((5(BaseEdge/2)) * math.sqrt((height**2)(((BaseEdge*math.tan(54 degrees))/2)**2)))

def SolveForSurfaceAreaRightPentagonalPyramid():
    print ("Solving for the surface area of a right pentagonal pyramid.")
#  Square root function: math.sqrt(x)
#  math.tan(x in radians) - returns tangent of "x" in radians

# Enter the length of the base edge and height
    BaseEdge = float(input("Enter the length of the base edge: ") )
    height = float(input("Enter the height: ") )

# Change 54 degrees to radians so that we can use the math.tan function
# Use math.radians() to convert degrees to radians
    FiftyFourInRadians = math.radians(54)
    print("54 in radians is: ", FiftyFourInRadians)
    # Now find the tangent
    Tangent54 = math.tan(FiftyFourInRadians)
    print("The tangent of 54 is: ", Tangent54)
    
#  Break equation into two parts to make it easier to calculate
#  Break into left side of equation and right side of equation
   # Calculate left side first
    LeftSideOfEquation = ((5/4) * (Tangent54) * (BaseEdge**2))
    print("Left side of the equation is: ", LeftSideOfEquation)

    #  Now calculate right side which is a little more complex
    TangentPortionRightSide = (((BaseEdge*Tangent54)/2)**2)
    SquareRootPortionPlusTangentPortion = math.sqrt(((height**2) + (TangentPortionRightSide)))
    FiveTimesBaseEdgeOver2 = (5 * (BaseEdge/2))
    RightSideOfEquation = (FiveTimesBaseEdgeOver2) * (SquareRootPortionPlusTangentPortion)
    print("Right side of the equation is: ", RightSideOfEquation)
    
    # Now combine left side and right side of equation to get the surface area
    SurfaceAreaRightPentagonalPyramid = LeftSideOfEquation + RightSideOfEquation
   
    print("The surface area of a right pentagonal pyramid is: ", SurfaceAreaRightPentagonalPyramid)
ContinueCalculations = "y"

# Check to see if the user wants to continue to calculate the Surface Area Right Pentagonal Pyramid
while (ContinueCalculations=="y"):
    SolveForSurfaceAreaRightPentagonalPyramid()
    ContinueCalculations = input("Would like to do another calculation for the Surface Area Right Pentagonal Pyramid? (y/n): ")
    
print("==================================")
print ("Thank you to <a href="http://www.Google.com"> www.Google.com </a> for assistance with this formula.")