计算每个月有多少天的python基础题

Year = int(input('请输入年份: '))

Month = int(input('请输入月份: '))

#31天的情况判断
if (Month == 1 or Month == 3 or Month ==5 or Month == 7 or Month == 8
        or Month == 10 or Month == 12):
    print('本月31天')
#30天的情况判断
elif (Month == 4 or Month == 6 or Month ==9 or Month == 11):
    print('本月30天')
#闰年2月判断
elif Month ==2 and ((Year % 4 == 0 and Year % 100 !=0 ) or Year % 400 == 0):
    print('本月29天')
#28天情况判断
else:
    print('本月28天')

 运行的结果如下

 

posted @ 2022-07-18 13:20  小白学程  阅读(1484)  评论(0)    收藏  举报