To calculate perimeter of rectangle in python, you have to ask from user to enter length and breadth of rectangle to calculate and print the perimeter of that rectangle as shown in the program given below.
Following python program ask from user to enter length and breadth of rectangle to find perimeter:
# Python Program - Calculate Perimeter of Rectangle print("Enter 'x' for exit."); leng = input("Enter length of rectangle: "); if leng == 'x': exit(); else: brea = input("Enter breadth of rectangle: "); length = int(leng); breadth = int(brea); perimeter = (2*length) + (2*breadth); print("\nPerimeter of Rectangle =", perimeter);
Here is the sample run of the above Python program shows how to calculate perimeter of rectangle:
Perimeter of a rectangle can be calculated either by following two ways:
perimeter = length+breadth+length+breadth
Or,
perimeter = (2 x length) + (2 x breadth)
Now you have to enter the length and breadth value of that rectangle whose perimeter you want to calculate using the above python program. Here is the sample run:
Here is the same program directly on python shell:
You may also like to learn or practice the same program in other popular programming languages: