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.
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:
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.
Below is the same program on python shell:
Program Video with Compile and Run
You may also like to learn or practice the same program in other popular programming languages: