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

python练习4

时间:2023-05-16 11:13:10浏览次数:39  
标签:Cexception python self 练习 legal month year day

python练习4

class Cexception :
def __init__(self,year,month,day):
if Cexception.judge(year,month,day) :
self.year = year
self.month = month
self.day = day
else:
self.year = -1
self.month = -1
self.day = -1
print("日期有误")
def setTime(self,year,month,day):
if Cexception.judge(year,month,day) :
self.year = year
self.month = month
self.day = day
else:
self.year = -1
self.month = -1
self.day = -1
print("日期有误")
def display(self):
if self.month ==-1 or self.year == -1 or self.day == -1:
print("",end="")
else:
print(str(self.month)+"/"+str(self.day)+"/"+str(self.year))
def judge(year,month,day):
leap = False
legal = False
if year>0:
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
leap = True
if month in [1, 3, 5, 7, 8, 10, 12]:
if 1 <= day <= 31:
legal = True
elif month in [4, 6, 9, 11]:
if 1 <= day <= 30:
legal = True
elif month == 2:
if not leap and 1 <= day <= 28:
legal = True
elif leap and 1 <= day <= 29:
legal = True
else:
legal = False
return legal

c = Cexception(-1,11,2)
c.display()
c = Cexception(2019,11,2)
c.display()
c = Cexception(2019,2,29)
c.display()
c = Cexception(2020,2,29)
c.display()

 

标签:Cexception,python,self,练习,legal,month,year,day
From: https://www.cnblogs.com/yunbianshangdadun/p/17404330.html

相关文章

  • 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\�......
  • Python自动化测试篇:Selenium
    所谓自动糊测试就是用程序模拟用户在浏览器上的操作,可以通过程序实现在文本框中自动输入内容,点击按钮等操作。一:安装chromedriverhttps://chromedriver.storage.googleapis.com/index.html或者https://npm.taobao.org/mirrors/chromedriver/下载和自己的浏览器版本号一致的驱......