~1 min read • Updated Sep 30, 2025
Program Overview
This Python program calculates the area of a trapezoid using the following formula:
s = h × (a + b) ÷ 2
Where a and b are the lengths of the two parallel sides, and h is the height.
The user enters these values, and the program computes and displays the result.
Python Code:
# Get input from user
a = float(input("Length of first parallel side (a): "))
b = float(input("Length of second parallel side (b): "))
h = float(input("Height (h): "))
# Calculate area
area = h * (a + b) / 2
# Display result
print("\n--- Result ---")
print(f"Trapezoid area: {area}")
Sample Output:
Length of first parallel side (a): 8
Length of second parallel side (b): 12
Height (h): 5
--- Result ---
Trapezoid area: 50.0
Explanation:
- The user enters the lengths of the two parallel sides and the height
- The program applies the trapezoid area formula directly
- The result is printed in a clear and readable format
Written & researched by Dr. Shahin Siami