codescracker


python

Python Program to Calculate Area of Square



« Previous Program Next Program »


Calculate Area of Square in Python

To calculate area of a square in python, you have to ask from user to enter the side length of square to calculate and print the area of that square on the output screen as shown in the program given below.

Python Programming Code to Calculate Area of Square

Following python program ask from user to enter side length of square to print area of the square:

# Python Program - Calculate Area of Square

print("Enter 'x' for exit.");
side = input("Enter side length of Square: ");
if side == 'x':
    exit();
else:
    side_length = int(side);
    area_square = side_length*side_length;
    print("\nArea of Square =",area_square);

Here is the sample run of the above Python program shows how to calculate and print area of a square:

calculate area of square python

Now enter the length or side length of the square to calculate and print it's area according to given side of the square as shown in the below sample output:

area of square python

Here is the same program with run on python shell:

python calculate area 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