I can't figure out why python keeps saying Rectangle
in x = Rectangle(6,8)
is undefined. The reason the x =
Rectangle(6,8)
is there is because the second part of the task it: After you make the two methods, make an instance of the Rectangle
class and set the value to have a length of 6 and width of 8. Afterward, print both the area and perimeter of the Rectangle
. There will be 3 other Instances below to test your code, so make sure you don't hard-code the answers.
My code:
class Rectangle:
def __init__(self,length,width):
self.length = length
self.width = width
def getArea(self):
area = self.length * self.width
return area
def getPerimeter(self):
perimeter = 2 * self.length + 2 * self.width
return perimeter
x = Rectangle(6,8)
print(x.getArea())
print(x.getPerimeter())