codescracker


python

Python Program to Calculate Area of Rectangle



« Previous Program Next Program »


Calculate Area of Rectangle in Python

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

Python Programming Code to Calculate Area of Rectangle

Following python program ask from user to enter length and breadth of rectangle to calculate area:

# Python Program - Calculate Area 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);
    area = length*breadth;
    print("\nArea of Rectangle =",area);

Here is the sample run of the above Python program shows how to calculate area of rectangle:

calculate area of rectangle python

Now enter length and breadth of that rectangle whose area you are going to find out using the above program. After entering length say 7 and breadth say 5, press enter key to see the area as shown in the below sample output:

area of rectangle python

Here is the same program with run on python shell:

python calculate area of rectangle

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