find the area of a trapezoid in python

To find the area of a trapezoid in Python, we can use the following formula:

main.py
Area = ((base1 + base2) * height) / 2
38 chars
2 lines

Where:

  • base1 and base2 are the lengths of the top and bottom of the trapezoid
  • height is the distance between the two bases

We can write a Python function to calculate the area of a trapezoid using this formula:

main.py
def trapezoid_area(base1, base2, height):
    area = ((base1 + base2) * height) / 2
    return area
100 chars
4 lines

We can then use this function to calculate the area of any trapezoid by passing in the values of its bases and height as arguments. For example:

main.py
# Example usage
trap_area = trapezoid_area(5, 7, 4)
print(trap_area)  # Output: 24.0
85 chars
4 lines

This would calculate the area of a trapezoid with bases of length 5 and 7 and a height of 4, and print the result (24.0).

gistlibby LogSnag