 # Python Program for Circumference of a Parallelogram

Given the sides of a parallelogram, the task is to calculate the circumference of a parallelogram for the given sides in python.

Circumference of Parallelogram:

A parallelogram’s opposite sides are equal in length and parallel. Angles are equal when paired, but not always at 90 degrees. The circumference of a parallelogram can be calculated by multiplying the sum of two adjacent sides by two.

Formula:

The circumference of parallelogram = (2*a)+(2*b)

where a, b are the sides of a parallelogram

Python round() function:

The round() function returns a floating-point number with the specified number of decimals that is a rounded version of the specified number.

Examples:

Example1:

Input:

Given first side = 5
Given second side = 6

Output:

The Circumference of a parallelogram for the given two sides{ 5 , 6 } =  22

Example2:

Input:

Given first side = 3.85
Given second side = 8.64

Output:

The Circumference of a parallelogram for the given two sides{ 3.85 , 8.64 } = 24.98

## Program for Circumference of a Parallelogram in Python

Below are the ways to calculate the circumference of a parallelogram for the given two sides in python:

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

Approach:

• Give the first side as static input and store it in a variable.
• Give the second side as static input and store it in another variable.
• Create a function to say parallelogram_circumference() which takes the given two sides as the argument and returns the circumference of the given parallelogram.
• Inside the function, calculate the circumference of the parallelogram using the above given mathematical formula and store it in another variable.
• Return the above result.
• Pass the given two sides as the arguments to the parallelogram_circumference() function and round it off to up to 3 places after the decimal point using the round() function.
• Store it in another variable.
• Print the above result which gives the circumference of the parallelogram for the given sides.
• The Exit of the Program.

Below is the implementation:

# Create a function to say parallelogram_circumference() which takes the given two
# sides as the argument and returns the circumference of the given parallelogram.

def parallelogram_circumference(fst_side, scnd_side):
# Inside the function, calculate the circumference of the parallelogram using the
# above given mathematical formula and store it in another variable.
paralgrm_circum = (2 * fst_side) + (2 * scnd_side)
# Return the above result.
return paralgrm_circum

# Give the first side as static input and store it in a variable.
fst_side = 5
# Give the second side as static input and store it in another variable.
scnd_side = 6
# Pass the given two sides as the arguments to the parallelogram_circumference() function
# and round it off to up to 3 places after the decimal point using the round() function.
# Store it in another variable.
circumfrnce = round(parallelogram_circumference(fst_side, scnd_side), 3)
# Print the above result which gives the circumference of the parallelogram for
# the given sides.
print(
"The Circumference of a parallelogram for the given two sides{", fst_side, ",", scnd_side, "} = ", circumfrnce)

#include <cmath>
#include <iostream>
using namespace std;

int main()
{
int fst_side = 5;
int scnd_side = 6;
int paralgrm_circum = (2 * fst_side) + (2 * scnd_side);
cout << "The Circumference of a parallelogram for the "
"given two sides{"
<< fst_side << "," << scnd_side
<< "} = " << paralgrm_circum << endl;
return 0;
}

Output:

The Circumference of a parallelogram for the given two sides{ 5 , 6 } =  22

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

Approach:

• Give the first side as user input using the float(input()) function and store it in a variable.
• Give the second side as user input using the float(input()) function and store it in another variable.
• Create a function to say parallelogram_circumference() which takes the given two sides as the argument and returns the circumference of the given parallelogram.
• Inside the function, calculate the circumference of the parallelogram using the above given mathematical formula and store it in another variable.
• Return the above result.
• Pass the given two sides as the arguments to the parallelogram_circumference() function and round it off to up to 3 places after the decimal point using the round() function.
• Store it in another variable.
• Print the above result which gives the circumference of the parallelogram for the given sides.
• The Exit of the Program.

Below is the implementation:

# Create a function to say parallelogram_circumference() which takes the given two
# sides as the argument and returns the circumference of the given parallelogram.

def parallelogram_circumference(fst_side, scnd_side):
# Inside the function, calculate the circumference of the parallelogram using the
# above given mathematical formula and store it in another variable.
paralgrm_circum = (2 * fst_side) + (2 * scnd_side)
# Return the above result.
return paralgrm_circum

# Give the first side as user input using the float(input()) function and store it in a variable.
fst_side = float(input("Enter some random number = "))
# Give the second side as user input using the float(input()) function and
# store it in another variable.
scnd_side = float(input("Enter some random number = "))
# Pass the given two sides as the arguments to the parallelogram_circumference() function
# and round it off to up to 3 places after the decimal point using the round() function.
# Store it in another variable.
circumfrnce = round(parallelogram_circumference(fst_side, scnd_side), 3)
# Print the above result which gives the circumference of the parallelogram for
# the given sides.
print(
"The Circumference of a parallelogram for the given two sides{", fst_side, ",", scnd_side, "} = ", circumfrnce)


Output:

Enter some random number = 3.85
Enter some random number = 8.64
The Circumference of a parallelogram for the given two sides{ 3.85 , 8.64 } = 24.98