python练习5
import mathclass Point():
def __init__(self,x,y):
self.x = x
self.y = y
def __lt__(self, other):
l1 = math.sqrt(self.x**2+self.y**2)
l2 = math.sqrt(other.x**2+other.y**2)
return l1<l2
def __le__(self, other):
l1 = math.sqrt(self.x**2+self.y**2)
l2 = math.sqrt(other.x**2+other.y**2)
return l1<=l2
def __gt__(self, other):
l1 = math.sqrt(self.x**2+self.y**2)
l2 = math.sqrt(other.x**2+other.y**2)
return l1>l2
def __ge__(self, other):
l1 = math.sqrt(self.x**2+self.y**2)
l2 = math.sqrt(other.x**2+other.y**2)
return l1>=l2
def __eq__(self, other):
l1 = math.sqrt(self.x**2+self.y**2)
l2 = math.sqrt(other.x**2+other.y**2)
return l1==l2
def __ne__(self, other):
l1 = math.sqrt(self.x**2+self.y**2)
l2 = math.sqrt(other.x**2+other.y**2)
return l1!=l2
p1 = Point(1,2)
p2 = Point(3,4)
p=p1<p2
print(p)
p=p1<=p2
print(p)
p=p1>p2
print(p)
p=p1>=p2
print(p)
p=p1==p2
print(p)
p=p1!=p2
print(p)
标签:__,python,self,练习,sqrt,other,l1,math From: https://www.cnblogs.com/yunbianshangdadun/p/17404335.html