Python 根据年月打印出对应的天数

Python 根据年月打印出对应的天数

1、闰年需要满足的条件:
1-1. 能被4整除,但不能被100整除;
1-2. 能被400整除;
2、月份满足的条件:
2-1. 闰年2月为29天,平年则为28天;
2-2. 1到7月,奇数月为31天,偶数月为30天;
2-3. 8到12月,奇数月为30天,偶数月为31天;
year=int(input("please enter year:"))
month=int(input("please enter month:"))
if month>12 or month<1:
    print("输入月有误")
elif month==2:
    if year%4==0 and year%100!=4 or year%400==0:
        print("{}年有29天".format(year))
    else:
        print("{}年有28天".format(year))
elif month%2==1 and month<=7:
    print("{}年{}月有31天".format(year,month))
elif month%2==0 and month<=7:
    print("{}年{}月有30天".format(year,month))
elif month%2==1 and month>=8:
    print("{}年{}月有30天".format(year,month))
else:
    print("{}年{}月有31天".format(year,month))

版权声明:本文为weixin_44956965原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。