Skip to main content

Create a Python class named Rectangle constructed by a length and width and a method that will compute the area of a rectangle.

· One min read
Kaustubh Kulkarni
file.py
class Rectangle:
def __init__(self, length, width):
self.length = length
self.width = width
def area(self):
return self.length * self.width
l=float(input("Please Enter Length of Rectangle : "))
w=float(input("Please Enter width of Rectangle : "))
r = Rectangle(l, w)
print("Area of Rectangle is :{} ".format(r.area()))

Output:

Output
Please Enter Length of Rectangle : 4
Please Enter width of Rectangle : 5
Area of Rectangle is :20.0