5.16博客

怎么到了实验室工程数学老师还是老转

国一游走名不虚传

python学习:

import math

class 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)

posted @ 2024-05-16 22:54  张佳木  阅读(10)  评论(0)    收藏  举报