completeclassrectanglecollection,whichhasonelistinstancevariable,rectangles, thatshouldinitiallyrefertoanemptylist.writeamethodadd _ rectanglethattakesarectangleasaparameterandappendsitotherectangles tsthattakesanumberasaparameterandreturnsalistofallrectanglesfromtherectangleslistthathavavity
class Rectangle:
' ' A rectangle with a width and height.' ' '
def __init__(self,w,h ) :
“”(Rectangle、number、number )
createanewrectangleofwidthwandheighth。
r=rectangle (1,2 ) ) ) ) ) ) )。
r.width
1
r.height
2
''''
self.width=w
self.height=h
defget_area(self ) :
“”(Rectangle )- number
返回the area of this rectangle。
r=rectangle (10,20 ) ) ) ) ) 0
r.get_area (
200
''''
return self.width * self.height
类复原收集3360
def __init__(self ) :
(“”(rectangle collection (-yj dhj/PRC=rectangle collection () ) ) ) ) ) ) ) )。
rc.rectangles
[]
''''