最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python設(shè)計(jì)并實(shí)現(xiàn)平面點(diǎn)類Point的源代碼

 更新時(shí)間:2024年05月08日 08:54:28   作者:不會(huì)JAVA的小袁  
這篇文章主要介紹了python-設(shè)計(jì)并實(shí)現(xiàn)平面點(diǎn)類Point,定義一個(gè)平面點(diǎn)類Point,對(duì)其重載運(yùn)算符關(guān)系運(yùn)算符,關(guān)系運(yùn)算以距離坐標(biāo)原點(diǎn)的遠(yuǎn)近作為基準(zhǔn),需要的朋友可以參考下

題目描述

定義一個(gè)平面點(diǎn)類Point,對(duì)其重載運(yùn)算符關(guān)系運(yùn)算符,關(guān)系運(yùn)算以距離坐標(biāo)原點(diǎn)的遠(yuǎn)近作為基準(zhǔn),遠(yuǎn)的為大。程序完成對(duì)其的測試。

【源代碼程序】

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)

運(yùn)行測試

到此這篇關(guān)于python設(shè)計(jì)并實(shí)現(xiàn)平面點(diǎn)類Point的源代碼的文章就介紹到這了,更多相關(guān)python平面點(diǎn)類Point內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

荣昌县| 扶风县| 阿尔山市| 翁源县| 宣武区| 阿城市| 繁峙县| 光山县| 肥乡县| 定南县| 来安县| 怀远县| 天全县| 霍州市| 章丘市| 临潭县| 余姚市| 西盟| 临夏市| 瓮安县| 嘉黎县| 隆德县| 金坛市| 洪泽县| 谢通门县| 花垣县| 扎赉特旗| 车险| 梧州市| 南雄市| 高陵县| 井陉县| 巨野县| 吕梁市| 福建省| 棋牌| 麻江县| 启东市| 黄骅市| 延长县| 道孚县|