# Python Program to find Area of a Trapezoid

How to write Python Program to find Area of a Trapezoid and Median of a Trapezoid with example. Before we step into practical Python Program to find Area of a Trapezoid example, Let see the definitions and formulas

## Python Area of a Trapezoid

If we know the height and two base lengths then we can calculate the Area of a Trapezoid using the below formula:

Area = (a+b)/2 * h

Where a and b are the two bases and h is the height of the Trapezoid. And, we can calculate the median of a Trapezoid using the following formula:

Median = (a+b) / 2.

If we know the Median and height then we can calculate the Area of a Trapezoid as: median * height

## Python Program to find Area of a Trapezoid

This python program allows the user to enter both sides of the Trapezoid and height. Using those values, this Python program will calculate the Area of a trapezoid and Median of a Trapezoid.

```# Python Program to find Area of a Trapezoid

base1 = float(input('Please Enter the First Base of a Trapezoid: '))
base2 = float(input('Please Enter the Second Base of a Trapezoid: '))
height = float(input('Please Enter the Height of a Trapezoid: '))

# calculate the area
Area = 0.5 * (base1 + base2) * height

# calculate the Median
Median = 0.5 * (base1+ base2)

print("\n Area of a Trapezium = %.2f " %Area)
print(" Median of a Trapezium = %.2f " %Median)```

The below statements will ask the user to enter base1, base2 and height values and it will assign the user input values to respected variables. Such as first value will be assigned to base1, second value to base2 and third value to height

```base1 = float(input('Please Enter the First Base of a Trapezoid: '))
base2 = float(input('Please Enter the Second Base of a Trapezoid: '))
height = float(input('Please Enter the Height of a Trapezoid: '))```

Next, we are calculating the Median and Area of a Trapezoid using their respective Formulas:

```# calculate the area
Area = 0.5 * (base1 + base2) * height

# calculate the Median
Median = 0.5 * (base1+ base2)```

Print statements will help us to print the Median and Area of a Trapezoid

```print("\n Area of a Trapezium = %.2f " %Area)
print(" Median of a Trapezium = %.2f " %Median)```

Let us see the Output of a Program

``````Please Enter the First Base of a Trapezoid: 6
Please Enter the Second Base of a Trapezoid: 9
Please Enter the Height of a Trapezoid: 4

Area of a Trapezium = 30.00
Median of a Trapezium = 7.50 ``````

From the above Python screenshot you can observe that, Values that we entered are base1 = 6, base2 = 9 and height = 4

Area of a Trapezoid = 0.5 * (base1 + base2) * height;
Area of a Trapezoid = 0.5 * (6 + 9) * 4;
Area of a Trapezoid = 0.5 * 15 * 4;
Area of a Trapezoid = 30

Median of a Trapezoid = 0.5 * (base1+ base2);
Median of a Trapezoid = 0.5 * (6 + 9)
Median of a Trapezoid = 0.5 * 15
Median of a Trapezoid = 7.5

## Python Program to find Area of a Trapezoid using functions

This python program allows the user to enter the base1, base2 and height of a Trapezoid. We will pass those values to the function arguments to calculate the area of a Trapeziod.

```# Python Program to find Area of a Trapezoid using Functions

def Area_of_a_Trapezoid (base1, base2, height):
# calculate the area
Area = 0.5 * (base1 + base2) * height

# calculate the Median
Median = 0.5 * (base1+ base2)

print("\n Area of a Trapezium = %.2f " %Area)
print(" Median of a Trapezium = %.2f " %Median)

Area_of_a_Trapezoid (9, 6, 4)```

In this Python Program to find Area of a Trapezoid example, First, We defined the function with three arguments using def keyword. It means, User will enter the base1, base2 and height of a Trapezoid. Next, We are Calculating the Median and Area of a Trapezoid as we described in our first example.

NOTE: We can call the function with arguments in .py file directly or else we can call it from the python shell. Please don’t forget the function arguments