How to find area of a rectangle in Python

An area of a rectangle is the measurement of the space that the rectangle occupies which can be in the form of square units such as square meters (m²), or square feet (ft²).

Image of Rectangle with its properties
Image of Rectangle with its properties

Formula to find an area

You can simply multiply the width of the rectangle by its height.

Area = Width * Height

Python code with default input

In the code below, we have given default values to the variables of width and height to calculate the area.

#you can give default input to the variables
width = 4
height = 5
# Now we are using the formula to calculate the Area
Area = width * height
# after calculating, simple print it in string
print("Area of rectangle = "+str(Area))

Python code with user input

In the code below, we can take input from the user and then apply the formula of an area on the values.

# In this way, you can take 2 separate inputs from user on console
# Wrtie 2 inputs in 2 separate lines
width = float(input())
height = float(input())
# Now we are using the formula to calculate the Area
Area = width * height
# after calculating, simple print it in string
print("Area of rectangle = " + str(Area))

Enter the input below

Ready to kickstart your career as a Python Developer? Our Become a Python Developer path is designed to take you from your first line of code to landing your first job.This comprehensive journey offers essential knowledge, hands-on practice, interview preparation, and a mock interview, ensuring you gain practical, real-world coding skills. With our AI mentor by your side, you’ll overcome challenges with personalized support, building the confidence needed to excel in the tech industry.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved