The area of a trapezoid can be calculated using the formula: area = ((base1 + base2) / 2) * height, where base1 and base2 are the lengths of the parallel sides, and height is the perpendicular distance between the bases.
def calculate_trapezoid_area(base1, base2, height):
return ((base1 + base2) / 2) * height
# Taking input for the lengths of the bases and height of the trapezoid and calculating its area
def calculate_and_display_trapezoid_area():
base1 = float(input("Enter the length of the first base: "))
base2 = float(input("Enter the length of the second base: "))
height = float(input("Enter the height of the trapezoid: "))
area = calculate_trapezoid_area(base1, base2, height)
print("Area of the trapezoid:", area)
calculate_and_display_trapezoid_area()
Enter the length of the first base: 5
Enter the length of the second base: 7
Enter the height of the trapezoid: 4
Area of the trapezoid: 24.0
Enter the length of the first base: 10.5
Enter the length of the second base: 8.2
Enter the height of the trapezoid: 6.3
Area of the trapezoid: 58.904999999999994
The function calculate_trapezoid_area(base1, base2, height)
calculates the area of a trapezoid using the formula ((base1 + base2) / 2) * height.
The function calculate_and_display_trapezoid_area()
takes input for the lengths of the bases and height of the trapezoid, calculates its area using the aforementioned function, and displays the result.