Python Program To Find Area And Perimeter Of Rectangle

Want to find the area and perimeter of rectangle in python then you are at the right place, today in this tutorial I will show you how to create a python program to find area and perimeter of rectangle.
A rectangle is a quadrilateral with four right angles. So our goal is to find the area and perimeter of the rectangle using python programming, so to do that we use the below formulas:
- Area = length * width
- Perimeter = 2 (length + width)
Above are the formulas that we will use to find the area and perimeter of a rectangle. Now let’s see how to do this in code.
Code For Python Program To Find Area And Perimeter Of A Rectangle
length = int(input('Length : '))
width = int(input('Width : '))
area = length * width
perimeter= 2 * (length + width)
print(f'Area of the Rectangle : {area}')
print(f'Perimeter of the Rectangle : {perimeter}')
Above is the python code to find the area and perimeter of a rectangle. First create a new folder for this program, open it in a code editor of your choice, I use vs code, create a python file and paste the above code.
To run this program you need python installed on your computer if you don’t have python installed read this guide: Install and setup python or you can use an online python compiler to run this program.
So to run this program on your computer, open a command prompt at your project folder location and paste the below command.
python filename.py
The above command will start the program and it will ask you to enter the length and width of the rectangle. After you enter, it will print the area and perimeter of the rectangle. Below is an example output:
Length : 10
Width : 5
Area of the Rectangle : 50
Perimeter of the Rectangle : 30
As you can see, it successfully prints the area and perimeter of a rectangle. I hope you were able to run this program successfully.
Summary
This was the python program to find the area and the perimeter of a rectangle. I hope you found this tutorial helpful and useful. Do share it with your friends who might be interested in this program.
Here are some more python tutorials you will find helpful:
- Vending Machine Program in python with code.
- Python program to wish happy new year.
- Create matrix effect using python.
- Create Joke generator using python with code.
I hope you found what you were looking for from this python tutorial and if you want more python tutorials like this, do join our Telegram channel for future updates.
Thanks for reading, have a nice day 🙂