codescracker


python

Python Program to Calculate Perimeter of Rectangle



« Previous Program Next Program »


Calculate Perimeter of Rectangle in Python

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.

Python Programming Code to Calculate Perimeter of Rectangle

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:

calculate perimeter of rectangle python

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:

perimeter of rectangle python

Here is the same program directly on python shell:

python calculate perimeter of rectangle

Program Video with Compile and Run

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test