Python Program to find Perimeter of a Rectangle using length and width

Write Python Program to find Perimeter of a Rectangle using length and width with a practical example.

Python Program to find Perimeter of a Rectangle using length and width example 1

This Python program allows user to enter the length and width of a rectangle. By using the length and width, this program finds the perimeter of a rectangle. The math formula to calculate perimeter of a rectangle: perimeter  = 2 * (Length + Width). If we know the length & width.

# Python Program to find Perimeter of a Rectangle using length and width

length = float(input('Please Enter the Length of a Triangle: '))
width = float(input('Please Enter the Width of a Triangle: '))

# calculate the perimeter
perimeter = 2 * (length + width)

print("Perimeter of a Rectangle using", length, "and", width, " = ", perimeter)
Please Enter the Length of a Triangle: 35
Please Enter the Width of a Triangle: 88
Perimeter of a Rectangle using 35.0 and 88.0  =  246.0

Python Program to calculate Perimeter of a Rectangle using length and width example 2

This Python program to find perimeter of a Rectangle is the same as above. But, in this python program, we separated the Perimeter of a rectangle logic using Python functions.

# Python Program to find Perimeter of a Rectangle using length and width

def perimeter_of_Rectangle(length, width):
    return 2 * (length + width)

length = float(input('Please Enter the Length of a Triangle: '))
width = float(input('Please Enter the Width of a Triangle: '))

# calculate the perimeter
perimeter = perimeter_of_Rectangle(length, width)
print("Perimeter of a Rectangle using", length, "and", width, " = ", perimeter)
Python Program to find Perimeter of a Rectangle using length and width 2

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.