find the surface area of a triangular prism in python

Here's a Python function that calculates the surface area of a triangular prism based on its base, height, and length:

main.py
import math

def surface_area_triangular_prism(base, height, length):
    # calculate the area of the triangular base
    base_area = 0.5 * base * height

    # calculate the area of the three rectangular faces
    side_face_area = base * length
    top_face_area = 0.5 * length * math.sqrt(height**2 + (base/2)**2)
    bottom_face_area = top_face_area

    # add up the areas of all faces
    total_area = 2 * side_face_area + top_face_area + bottom_face_area + base_area

    return total_area
496 chars
16 lines

To use this function, simply call it with the appropriate parameters:

main.py
# example usage
base = 4
height = 5
length = 6

print(surface_area_triangular_prism(base, height, length)) # Output: 97.19896192924605
135 chars
7 lines

gistlibby LogSnag