You are on page 1of 5

def main(): print "Rectangle a:" a = Rectangle(5, 7) print "area: %d" % a.area print "perimeter: %d" % a.

perimeter print "" print "Rectangle b:" b = Rectangle() b.width = 10 b.height = 20 print b.getStats()

From this main function, which I should not change, I am supposed to get this as an expected output:

When the Rectangle class has been properly created, the output should look like the following:
Rectangle a: area: 35 perimeter: 24 Rectangle b: width: 10 height: 20 area: 200 perimeter: 60

This is the Code Ive built, but it doesnt work class rectangle: def __init__(self, Rectangle = 'b'): self._Rectangle = Rectangle

def width(self): self.width = width

return width

def height(self): self.height = height return height

def main(): print "Rectangle a:" a = Rectangle(5, 7) print "area: %d" % a.area

print "perimeter: %d" % a.perimeter

print "" print "Rectangle b:" b = Rectangle() b.width = 10 b.height = 20 print b.getStats()

if __name__ == "__main__": main()

This is another code Ive tried, but it also doesnt work:

class Rectangle(): def __init__(self, width = '10'): self._width = width

def __init__(self, height = 20): object.__init__(self) self.setHeight(height)

def set_Width(self, width): if (width <= 0): print "Width must be larger than 0." print "Setting width to 10." self.width = 10 else: self.width = width

def get_Width(self): return self.width

def setHeight(self, height): if (height <=0): print "Height must be larger than 0." print "Setting height to 20" self.height = 20 else: self.height = height

def getHeight(self): return self.height

def getStats(): print "width" print "height" print "perimeter: ((width*2)+(height*2))" print "area: (width*height)"

def main():

print "Rectangle a:" a = Rectangle(5, 7) print "area: %d" % a.area

print "perimeter: %d" % a.perimeter

print "" print "Rectangle b:" b = Rectangle() b.width = 10 b.height = 20 print b.getStats()

if __name__== "__main__": main()

You might also like