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²).
You can simply multiply the width of the rectangle by its height.
Area = Width * Height
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 variableswidth = 4height = 5# Now we are using the formula to calculate the AreaArea = width * height# after calculating, simple print it in stringprint("Area of rectangle = "+str(Area))
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 lineswidth = float(input())height = float(input())# Now we are using the formula to calculate the AreaArea = width * height# after calculating, simple print it in stringprint("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