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

求python3问题完成啊classRectangle:"""Arectanglewithawidthandheight."""definit(self,w,h):"""(Rectangle,number,number)Createanewrectangleofwidthwandheighth.>>>r=Rectangle(1,2)

题目详情
求python3问题完成啊
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
"""
▼优质解答
答案和解析

太简单,我都差点不好意思回答了。

def area(self):
        """ (Rectangle) -> number

        Return the area of this rectangle.
        >>> r = Rectangle(10, 20)
        >>> r.area()
        200
        """
        return self.width * self.height