用python从键盘随机输入一个年份,输出该年有多少天(考虑闰年)?

如题所述

使用python标准库判断闰年

import calendar
year = 2019
if calendar.isleap(year):
   day_num=365
else:
   day_num=366

calendar库中的闰年算法

def isleap(year):
   """Return True for leap years, False for non-leap years."""
   return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)

温馨提示:答案为网友推荐,仅供参考
相似回答