Python program to find the area and perimeter of a rectangle

 

Python program to find the area and perimeter of a rectangle

Problem Definition:

Write a python program that has a class named Rectangle with attributes length and breadth and two methods area and perimeter they return area and perimeter respectively.

Video Tutorial:

Program source code for Python program to find the area and perimeter of a rectangle

class Rectangle: def __init__(self, length, breadth): self.length = length self.breadth = breadth def display(self): print ("Length of Rectangle is: ", self.length) print ("Breadth of Rectangle is: ", self.breadth) def area(self): return (self.length*self.breadth) def perimeter(self): return (2*self.length + 2*self.breadth) l = int (input("Enter the length of the Rectangle: ")) b = int (input("Enter the breadth of rectangle: ")) r1 = Rectangle(l , b) print ("Rectangle object details are:") r1.display() print("") print ("Area of Rectangle is: ", r1.area()) print("") print ("The Perimeter of the Rectangle is: ", r1.perimeter())

Output:

Enter the length of the Rectangle: 10

Enter the breadth of rectangle: 5

Rectangle object details are:

Length of Rectangle is: 10

The breadth of Rectangle is: 5

Area of Rectangle is: 50

The perimeter of the Rectangle is: 30

Summary:

This article discusses, how to write a Python program to calculate the area and perimeter of a rectangle. Subscribe to our YouTube channel for more videos and like the Facebook page for regular updates.

Leave a Comment

Welcome to VTUPulse.com


Download Final Year Project -> Click Here

This will close in 12 seconds