# Perimeter of trapezoid – Python Program to Compute the Perimeter of Trapezoid

Perimeter of trapezoid: In the previous article, we have discussed Python Program to Compute 1/N!
Trapezoid:

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

Formula to calculate Perimeter of a Trapezoid :

Perimeter (P) = a+b+c+d

where a, b = Bases of Trapezoid

c, d = Side length of Trapezoid
Given the values of a, b, c, d, and the task is to calculate the perimeter of the given Trapezoid.

Examples:

Example1:

Input:

Given a= 10
Given b= 20
Given c= 35
Given d= 45

Output:

The Trapezoid's perimeter with the given values of a,b,c,d { 10 20 35 45 } = 110

Example2:

Input:

Given a= 43
Given b= 17
Given c=  25.5
Given d= 32

Output:

The Trapezoid's perimeter with the given values of a,b,c,d { 43 17 25.5 32 } = 117.5

## Program to Compute the Perimeter of Trapezoid in Python

Below are the ways to calculate the perimeter of the given Trapezoid:

### Method #1: Using Mathematical Formula (Static Input)

Approach:

• Give the first base of the trapezoid as static input and store it in a variable.
• Give another base of the trapezoid as static input and store it in another variable.
• Give the first side length of the trapezoid as static input and store it in a variable.
• Give another side length of the trapezoid as static input and store it in another variable.
• Calculate the perimeter of the given trapezoid using the above given mathematical formula.
• Store it in another variable.
• Print the Trapezoid’s perimeter with the given values of bases and side lengths.
• The Exit of the program.

Below is the implementation:

# Give the first base of the trapezoid as static input and store it in a variable.
gvn_a = 10
# Give another base of the trapezoid as static input and store it in another variable.
gvn_b = 20
# Give the first side length of the trapezoid as static input and store it in a variable.
gvn_c = 35
# Give another side length of the trapezoid as static input and store it in another variable.
gvn_d = 45
# Calculate the perimeter of the given trapezoid using the above given mathematicalformula.
# Store it in another variable.
Trapzod_perimetr = gvn_a+gvn_b+gvn_c+gvn_d
# Print the Trapezoid's perimeter with the given values of bases and side lengths.
print(
"The Trapezoid's perimeter with the given values of a,b,c,d {", gvn_a, gvn_b, gvn_c, gvn_d, "} =", Trapzod_perimetr)


Output:

The Trapezoid's perimeter with the given values of a,b,c,d { 10 20 35 45 } = 110

### Method #2: Using Mathematical Formula (User Input)

Approach:

• Give the first base of the trapezoid as user input using the float(input()) function and store it in a variable.
• Give another base of the trapezoid as user input using the float(input()) function and store it in another variable.
• Give the first side length of the trapezoid as user input using the float(input()) function and store it in a variable.
• Give another side length of the trapezoid as user input using the float(input()) function and store it in another variable.
• Calculate the perimeter of the given trapezoid using the above given mathematical formula.
• Store it in another variable.
• Print the Trapezoid’s perimeter with the given values of bases and side lengths.
• The Exit of the program.

Below is the implementation of the above given approach:

# Give the first base of the trapezoid as user input using the float(input()) function
# and store it in a variable.
gvn_a = float(input("Enter some random variable = "))
# Give another base of the trapezoid as user input using the float(input()) function
# and store it in another variable.
gvn_b = float(input("Enter some random variable = "))
# Give the first side length of the trapezoid as user input using the float(input())
# function and store it in a variable.
gvn_c = float(input("Enter some random variable = "))
# Give another side length of the trapezoid as user input using the float(input())
# function and store it in another variable.
gvn_d = float(input("Enter some random variable = "))
# Calculate the perimeter of the given trapezoid using the above given mathematicalformula.
# Store it in another variable.
Trapzod_perimetr = gvn_a+gvn_b+gvn_c+gvn_d
# Print the Trapezoid's perimeter with the given values of bases and side lengths.
print(
"The Trapezoid's perimeter with the given values of a,b,c,d {", gvn_a, gvn_b, gvn_c, gvn_d, "} =", Trapzod_perimetr)


Output:

Enter some random variable = 43
Enter some random variable = 12.6
Enter some random variable = 4.9
Enter some random variable = 20
The Trapezoid's perimeter with the given values of a,b,c,d { 43.0 12.6 4.9 20.0 } = 80.5

Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.