Python Program to Find the Area of Rectangle

Python program to find area and perimeter of rectangle; Through this tutorial, i will show you how to obtain height and width of a rectangle and calculate or find its area and perimeter of rectangle in python program.

Note that:- To find the area of a rectangle, multiply the length by the width. And the formula of calculate or find Area of Rectangle is; as shown below:

Area = Width * Height

Perimeter is the distance around the edges. You can calculate or find perimeter of a rectangle using the following formula in program:

Perimeter = 2 * (Width + Height)

Python Program to Calculate the Area of Rectangle

  • Python Program to find the Area of a Rectangle and Perimeter of a Rectangle
  • Python Program to Calculate the Area of a Rectangle using Function

Python Program to find the Area of a Rectangle and Perimeter of a Rectangle

Now, i will write a program to find the Area of a Rectangle and Perimeter of a Rectangle in Python:

  • Get input the Width and Height of a rectangle in program from user.
  • Calculate or find the area as per the formula Area = width * height.
  • Calculate or find the Perimeter of a rectangle Perimeter = 2 * (width + height).
  • Print the Perimeter and Area of a rectangle.
# Write a Program to find the Area of a Rectangle and 
# Perimeter of a Rectangle in Python
w = float(input('Please Enter the Width of a Rectangle: '))
h = float(input('Please Enter the Height of a Rectangle: '))
# calculate the area
Area = w * h
# calculate the Perimeter
Perimeter = 2 * (w + h)
print("\n Area of a Rectangle is: %.2f" %Area)
print(" Perimeter of Rectangle is: %.2f" %Perimeter)

After executing the python program, the output will be:

Please Enter the Width of a Rectangle:  10
Please Enter the Height of a Rectangle:  5

Area of a Rectangle is: 50.00
Perimeter of Rectangle is: 30.00

Python Program to Calculate the Area of a Rectangle using Function

Use the following steps to calculate the area of a rectangle using function in python:

  • Defined the function with two arguments using def keyword.
  • Find the perimeter and Area of a rectangle inside functions.
  • Get input the Width and Height of a rectangle from user.
  • Print the Perimeter and Area of a rectangle.
# Write a Program to find the Area of a Rectangle and 
# Perimeter of a Rectangle in Python using functions
def AreaOfRectangle(width, height):
    # calculate the area
    Area = width * height
    # calculate the Perimeter
    Perimeter = 2 * (width + height)
    print("\n Area of a Rectangle is: %.2f" %Area)
    print(" Perimeter of Rectangle is: %.2f" %Perimeter)
    
width = float(input('Please Enter the Width of a Rectangle: '))
height = float(input('Please Enter the Height of a Rectangle: '))
AreaOfRectangle(width, height)

After executing the python program, the output will be:

Please Enter the Width of a Rectangle:  15
Please Enter the Height of a Rectangle:  5

 Area of a Rectangle is: 75.00
 Perimeter of Rectangle is: 40.00

Recommended Python Tutorials

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *