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

python設計并實現(xiàn)平面點類Point的源代碼

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

題目描述

定義一個平面點類Point,對其重載運算符關系運算符,關系運算以距離坐標原點的遠近作為基準,遠的為大。程序完成對其的測試。

【源代碼程序】

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)

運行測試

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

相關文章

最新評論

颍上县| 无为县| 嘉义县| 淅川县| 盐亭县| 鄯善县| 庐江县| 鄂托克前旗| 安陆市| 浦县| 远安县| 阳朔县| 汉阴县| 南郑县| 柳林县| 伊吾县| 遵义市| 临朐县| 天气| 兰州市| 五指山市| 波密县| 黔东| 罗江县| 衡南县| 扎兰屯市| 盘锦市| 昌都县| 缙云县| 石嘴山市| 崇左市| 梨树县| 襄城县| 中超| 平南县| 马公市| 吴江市| 灌阳县| 彩票| 宁城县| 济宁市|