类的组合

from math import pi


class Circle:
    def __init__(self, r):
        self.r = r

    def area(self):
        return pi*self.r*self.r

    def per(self):
        return 2*pi*self.r


class Ring:
    def __init__(self, outside_r, inside_r):
        self.outside_c = Circle(outside_r)
        self.inside_c = Circle(inside_r)

    def area(self):
        return self.outside_c.area() - self.inside_c.area()

    def pers(self):
        return self.outside_c.per() + self.inside_c.per()


ring = Ring(20, 10)
ret = ring.area()
print(ret)

 

posted @ 2019-02-15 21:20  飞蝎儿  阅读(102)  评论(0编辑  收藏  举报