from functools import total_ordering
from abc import ABCMeta,abstractmethod
@total_ordering
class Shape(object):
    @abstractmethod
    def area(self):
        pass
    def __eq__(self,obj):
        return self.area()==obj.area()
    def __lt__(self,obj):
        return self.area()<obj.area()

class Rectangle(Shape):
    def __init__(self,w,h):
        self.w=w
        self.h=h
    def area(self):
        return self.w*self.h
class Circle(Shape):
    def __init__(self,r):
        self.r=r
    def area(self):
        return 3.14*self.r*self.r    

r1=Rectangle(5,1)        
r2=Rectangle(1,4)  
c1=Circle(4)
c2=Circle(3)  
print(r1>=r2,c1>c2)  

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-12-23
  • 2022-01-22
猜你喜欢
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2022-02-26
  • 2022-12-23
相关资源
相似解决方案