早教吧 育儿知识 作业答案 考试题库 百科 知识分享

python问题求解答classRectangle:"""Arectanglewithawidthandheight."""definit(self,w,h):"""(Rectangle,number,number)Createanewrectangleofwidthwandheighth.>>>r=Rectangle(1,2)>>>

题目详情
python问题求解答
class Rectangle:
""" A rectangle with a width and height. """
def __init__(self, w, h):
""" (Rectangle, number, number)
Create a new rectangle of width w and height h.
>>> r = Rectangle(1, 2)
>>> r.width
1
>>> r.height
2
"""
self.width = w
self.height = h
def area(self):
""" (Rectangle) -> number
Return the area of this rectangle.
>>> r = Rectangle(10, 20)
>>> r.area()
200
"""
return self.width * self.height
class RectangleCollection:
def __init__(self):
""" (RectangleCollection) -> NoneType
>>> rc = RectangleCollection()
>>> rc.rectangles
[]
"""
▼优质解答
答案和解析
请详细描述你的疑问?
以便解决!