A Rectangle is a planar shape which have its opposite sides being equal like a closed shape having sides as 3, 3, 6, 6 with opposite sides being equal will be a Rectangle. Mathematically Perimeter of Rectangle can be calculated by just adding all of four sides. For example – If rectangle have sides 7, 7, 4, 4 then perimeter will be 7 + 7 + 4 + 4 = 22, in order words if rectangle have sides defined as x, x, y, y where x is length and y is height => then perimater will be 2 * (x + y). Quite simple mathematical formula for calculating perimeter of rectangle.
Let’s program this as Python Code for Finding Perimeter of Rectangle.
# Calculating Perimeter of Rectangle Using Python x = float(input("Enter Length of Rectangle => ")) y = float(input("Enter Height of Rectangle => ")) # Perimeter of Rectangle perimeter_of_rectangle = 2 * (x + y) # Printing out parameter of Rectangle print("Perimeter of Rectangle is =>", perimeter_of_rectangle)
Output of Above Code
Enter Length of Rectangle => 3 Enter Height of Rectangle => 4 Perimeter of Rectangle is => 14.0