首页 > 编程语言 >python判断随机年份是否为平年或者闰年,同时求的每个月的天数

python判断随机年份是否为平年或者闰年,同时求的每个月的天数

时间:2023-01-08 20:11:50浏览次数:41  
标签:闰年 python 31 30 month year print 平年

#求闰年和平年
 year=random.randint(1900,2023)
 if (year % 4 ==0 and year % 100 !=0) or (year % 400 ==0):
     print(f'{year}年是百年一遇的闰年,顺顺利利')
 else:
     print(f'现在是{year}年,是平年,平平安安!')
#根据平年闰年求每个月的天数
 year=random.randint(1000,2023)
 month=random.randrange(1,13)
 month_31=[1,3,5,7,8,10,12]
 month_30=[4,6,9,11]

 if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
     if month in month_31:
         print(f'{year}年的{month}月有31天,是润年,平平安安!')
     elif month in month_30:
         print(f'{year}年的{month}月有30天,是润年,快快乐乐!')
     else:
         print(f'{year}年的{month}月有29天,是润年,顺顺利利!')
 else:
     if month in month_31:
         print(f'{year}年的{month}月有31天,是平年,平平安安!')
     elif month in month_30:
         print(f'{year}年的{month}月有30天,是平年,快快乐乐!')
     else:
         print(f'{year}年的{month}月有28天,是平年,快快乐乐!')

 

标签:闰年,python,31,30,month,year,print,平年
From: https://www.cnblogs.com/ygyalex/p/17035238.html

相关文章

  • Python----存取款练习
    my_money=100atm_money=0#存款函数defsave_money():globalmy_money,atm_moneynum=int(input("请输入您要存款的金额:"))ifnum<=my_mone......
  • Python如果利用海龟turtle来绘制奥运五环
    #导入工具importturtle#奥运五环turtle.screensize(800,800)turtle.pensize(10)#中间黑色的圆turtle.pencolor('black')turtle.circle(100)#左边蓝色的圆turt......
  • Python海龟绘画制图的相关代码
    #导入工具#importturtle#定义一个画布尺寸的两种方式turtle.screensize(100,100)turtle.setup(800,600,700,200)#定义画笔turtle.shape('turtle')#定义画笔颜色......
  • 【Python】输入并查看数据类型
    print(type(1))----返回intprint(type('您好'))----返回str字符串print(type(0>1))------返回bool布尔类型print(type(3.145))------返回float浮点类型prin......
  • 【Python】算数运算符的区别
    #算数运算符的区别#数值+布尔真为1假为0print(1+True)#在字符串里面+作为连接符使用print('你'+'好'+'!')#在字符串里面用乘号,输入该字符串三次print('您好\n'*3......
  • 离线安装Python包
    起因需要在一台联网的计算机和一台不联网的计算机上安装Python包。pygame在线安装失败在CMD命令行运行下列命令安装pygame:python-mpipinstall--userpygame......
  • python爬虫
    信息表示方式Python库静态网页urlib、requests、BeautifulSoup、re动态网页Selenium和PhantomJS爬虫框架Scrapy数据存储CSV文件、TXT文本或JSON......
  • Python接口自动化系列- python+unittest+ddt参数化7
    一、ddt说明一般进行接口测试时,每个接口的传参都不止一种情况,一般会考虑正向、逆向等多种组合。所以在测试一个接口时通常会编写多条case,而这些case除了传参不同外,其实并......
  • Python中 re.compile 函数的使用
    以下介绍在python的re模块中怎样应用正则表达式1.使用re.compilere模块中包含一个重要函数是compile(pattern[,flags]),该函数根据包含的正则表达式的字符串创建模式......
  • Python基础中的基础:基本运算符的用法
    1算术运算符算术运算符只能用来将同数据类型的进行计算salary=3.3res=salary*12print(10+1)#11print(10-3)#7print(10*3)#30print(10/3)......