首页 > 编程语言 >python练习5

python练习5

时间:2023-05-16 11:14:11浏览次数:36  
标签:__ python self 练习 sqrt other l1 math

python练习5

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,self,练习,sqrt,other,l1,math
From: https://www.cnblogs.com/yunbianshangdadun/p/17404335.html

相关文章

  • python练习4
    python练习4classCexception:def__init__(self,year,month,day):ifCexception.judge(year,month,day):self.year=yearself.month=monthself.day=dayelse:self.year=-1self.mont......
  • python学生管理系统笔记(基础框架)
     1.LoginPage.pyimporttkinterastkfromtkinterimportmessageboxfromdbimportdbfromMainPageimportMainPageclassLoginPage:def__init__(self,master):self.root=masterself.root.geometry('300x180')se......
  • Python多线程并发通用模板
    多线程可以同时处理多个任务,支持并发处理,从而提高系统的并发能力。多线程爬虫的好处主要有提高爬取效率、提高稳定性、节省资源等。总之,多线程爬虫可以提高爬取效率、稳定性和资源利用率,是一种更加高效、可靠的爬虫实现方式。多线程爬虫并行可以提高爬虫的效率,具体实现方法如下:......
  • Python_报错:curl: (7) Failed to connect to raw.githubusercontent.com port 443: Op
    解决:https://blog.csdn.net/Jimmmyking/article/details/126105788作为mac的用户,如果你还没安装Homebrew那真的就太遗憾了,应为其真的很好用,然后安装Homebrew有时候有不是那么简单,会出现很多奇奇怪怪的错误,如下是我本人第一次安装就成功,其重要用的是中科大的brew主体,使用这个只需......
  • Python金融应用编程:衍生品定价和套期保值的随机过程|附代码数据
    全文链接:http://tecdat.cn/?p=5620最近我们被客户要求撰写关于金融应用编程的研究报告,包括一些图形和统计输出。在本文中随机过程对定量融资的许多方面都很有用,包括但不限于衍生品定价,风险管理和投资管理这些应用程序将在本文后面进一步详细讨论。本节介绍了量化融资中使用的一......
  • python 中 pyfaidx 模块统计fasta文件每一条染色体的长度
     001、python版本和pip版本a、python版本[root@PC1pip]#python--versionPython3.11.3 b、pip版本[[email protected]]#pip--versionpip23.1.2from/usr/local/lib/python3.11/site-packages/pip(python3.11) 002、利用pip安装 pyfaidx模块......
  • ERROR: Command errored out with exit status 1: python setup.py egg_info Check th
     001、在利用python2.7环境下利用pip安装pyfaidx模块时报如下错误:ERROR:Commanderroredoutwithexitstatus1:pythonsetup.pyegg_infoCheckthelogsforfullcommandoutput. 002、查看pip版本[root@PC1pip]#pip--versionpip20.3.4from/usr/lib/pyth......
  • 离线安装python模块
    安装环境32位win7电脑+python3.7.5模块来源(1)https://www.lfd.uci.edu/~gohlke/pythonlibs(2)https://pypi.org/安装numpy-1.21.6——直接安装pandas-1.3.5——所需支持:numpy-1.21.6,cython-0.29.30,six-1.16.0,python-dateutil-2.8.2,pytz2023.3matplotlib-2.2.5——所需支持:n......
  • Python_mac在编辑~/.bash_profile文件时,导致所有命令都不能用了
    原因:~/.bash_profile文件改坏了操作:1.在终端输入exportPATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin",命令暂时可以用了2.在终端输入open-e~/.bash_profile在文本编辑器里面打开.bash_profile文件3.检查修改配置文件问题,然后保存,由于本人是bas......
  • Python数据库篇:sqlite3、mysql、sqlalchemy
    一:sqlite3importsqlite3conn=sqlite3.connect("test.db")cursor=conn.cursor()cursor.execute("createtableuser(idvarchar(20)primarykey,namevarchar(20))")cursor.execute("insertintouser(id,name)values(\'1\�......