On Sat, 01 Nov 2014 12:00:46 -0400, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote:
>On Fri, 31 Oct 2014 19:32:13 -0400, Seymore4Head ><Seymore4Head@Hotmail.invalid> declaimed the following: > >> >>class Rectangle(object): >> def __init__(self, length, width=None): >> self.length = length >> if width is None: >> self.width = length >> else: >> self.width = width >> def area(self): >> return self.length * self.width >> def perimeter(self): >> return 2 * (self.length + self.width) >> >>class Square(Rectangle): >> def area(self): >> return self.length * self.width >> def perimeter(self): >> return 2 * (self.length + self.width) >> > Why did you redefine area and perimeter? Those are supposed to be >inherited operations from Rectangle. You've duplicated what should not have >been changed, and removed everything that makes a Square a Square. > > The "assignment" was to create a Square class that enforces the >property of "squareness" (length = width, or a simple "side"). > > What you created does not do that. > >>a=Rectangle(3,5) >>print (a.area()) >>print (a.perimeter()) >>b=Rectangle(5,7) >>print (b.area()) >>print (b.perimeter()) >>c=Square(4) >>print (c.area()) >>print (c.perimeter()) > > You're tests ignore the case of /changing/ side/length/width... >Consider what happens if you execute > >c.length = 5 >c.width = 9 > OK Maybe I misunderstood the question. My answer to you then is ......I don't know. I will have to think about it some more. -- https://mail.python.org/mailman/listinfo/python-list