Write a Python class named Rectangle constructed by a length and width and a method area which will compute the area of a rectangle. Note that length and width should be defined as instance attribute.
Also, define the docstring of the class, and a class attribute whose name is shape, and value is Rectangle. Define a method shape Type which will print out the value of the class attribute shape.
# Rectangle class definition
class Rectangle:
“””
This is a class for Rectangle to calculate the area
Attributes:
length: The length of the rectangle
width: The width of the rectangle
“””
# class attribute shape
shape=”Rectangle”
# constructor to initialize instance variables
def __init__(self,length,width):
self.length=length
self.width=width
# method to calculate and return area
def area(self):
return self.length*self.width
# shapeType() method
def shapeType(self):
print(“Shape type is”,self.shape)
def main():
# create an instance of Rectangle class
r=Rectangle(5,4)
# display class docs
print(Rectangle.__doc__)
# call ShapeType() method
r.shapeType()
# call area() method
print(“Area:”,r.area())
# calling main() function
main()