Site icon TestingDocs.com

Python Area of a Rectangle

Python Area of a Rectangle

Let’s write a simple Python program to find the area of a rectangle and understand the mathematical formula for computing its area.

Area of the Rectangle

The mathematical formula is as follows:

area = length * breadth

To compute, we need two input values for the program. We need to read the length and breadth of the rectangle from the user.

Python Program

In this tutorial, we will use Python IDLE as the code editor to write and run the code. Launch the IDLE tool and write the code. to create a new script, choose File -> New File. Save the file with the .py file extension.

The program to calculate the area is as follows:

 

# Python program to find the area of a rectangle

length = float(input('Enter length := ')) # read length

breadth = float(input('Enter breadth := ')) # read breadth

area = length * breadth # computation

print('Area of the Rectangle := ', area) # print rectangle area

 

Program Output

Run the program to view the output.

Enter length := 23.56
Enter breadth := 12.72
Area of the Rectangle := 299.6832

 

Python Tutorials

Python Tutorial on this website can be found at:

https://www.testingdocs.com/python-tutorials/

More information on Python is available at the official website:

https://www.python.org

Exit mobile version