codescracker


python

Python Program to Calculate Perimeter of Square



« Previous Program Next Program »


Calculate Perimeter of Square in Python

To calculate perimeter of square in python, you have to ask from user to enter side length of square to calculate perimeter of that square as shown in the program given here.

Python Programming Code to Calculate Perimeter of Square

Following python program ask from user to enter side length of square to calculate perimeter:

# Python Program - Calculate Perimeter of Square

print("Enter 'x' for exit.");
side = input("Enter side length of square: ");
if side == 'x':
    exit();
else:
    slength = int(side);
    perimeter = 4*slength;
    print("\nPerimeter of Square =", perimeter);

Here is the sample run of the above Python program shows how to calculate perimeter of square:

calculate perimeter of square python

Above is the initial output, now enter the side length of that square whose perimeter you want to find out. As you all know that perimeter of a square can be calculated by adding all the four side or just by multiplying any side by 4.

Therefore if a square has side length as 4 meter then its perimeter will be 4+4+4+4 is equal to 16 or 4x4 is also equal to 16.

Here is the sample run of the above program calculating and printing perimeter of a square.

perimeter of square python

Below is the same program on python shell:

python calculate perimeter of square

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