Sunday, 23 January 2022

Python-Slip21a-Define a class named Rectangle which can be constructed by a length and width. The Rectangle class has a method which can compute the area and Perimeter.

 Define a class named Rectangle which can be constructed by a length and width. The Rectangle class has a method which can compute the area and Perimeter.

import math

class Rectangle():

    def __init__(self,length,width):

        self.length=length

        self.width=width

       

    def area(self):

        return self.length*self.width

    def Perimeter(self):

        return 2*(self.length+self.width)

 

l=int(input("Enter length of Rectangle: "))

w=int(input("Enter width of Rectangle: "))

obj=Rectangle(l,w)

 

print("Area of Rectangle:",round(obj.area(),2))

 

print("Perimeter of Rectangle:",round(obj.Perimeter(),2))