Write a Python Program to find the 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
This Python program allows the 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 the perimeter of a rectangle is: 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 the 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)