Python program to calculate the area of a trapezoid

In this tutorial, we are going to learn how can we calculate the area of the trapezoid in python.

How to calculate the area of the trapezoid in Python

Before jump into the code let’s know what is a trapezoid:

A trapezoid is a geometrical figure with four sides in which two sides are parallel to each other. the sides that are parallel to each other known as ” base”. The other sides are known as  ” legs” (which may or may not be equal).

The formula for the area of a trapezoid:



Calculate the area of a trapezoid in Python

trapezoid shape

Area:
      (a+b)*h/2
       where a,b are the base and h is distance between two parallel lines

now let’s move on coding part:

1st take input as a base of a trapezoid form the users:

#parellel sides of the trapezoid:
Base1 = float(input('Enter the First Base of a Trapezoid: '))
Base2 = float(input('Enter the Second Base of a Trapezoid: '))

now take the height of trapezoid from users:

#distance between  two parallel sides
Height_of_Trapezoid= float(input('Enter the Height of a Trapezoid'))

calculate the area of the trapezoid using above formula;

# calculate the area of trapezoid
area = 0.5 * (Base1 + Base2) * Height

finally, print the result by using the print function :

print("The Area of a trapezoid ",area)

Combining the whole parts of the program:

#parellel sides of the trapezoid:
Base1 = float(input('Enter the First Base of a Trapezoid: '))
Base2 = float(input('Enter the Second Base of a Trapezoid: '))
#distance between  two parelle sides
Height_of_Trapezoid= float(input('Enter the Height of a Trapezoid'))

# calculate the area of trapezoid
area = 0.5 * (Base1 + Base2) * Height

print("The Area of a trapezoid ",area)

Output:

Enter the First Base of a Trapezoid: 6
Enter the Second Base of a Trapezoid: 5
Enter the Height of a Trapezoid: 3
The area of a Trapezium will be  16.5

Learn more python tutorials:

Leave a Reply

Your email address will not be published. Required fields are marked *