import time
# 获取当前日期
now = time.strftime("%Y/%m/%d")
year, month, day = now.split("/")
year = int(year)
month = int(month)
day = int(day)
# 判断是否为闰年
def is_leap_year(n):
if (n % 4 == 0 and n % 100 != 0) or n % 400 == 0:
return True
else:
return False
# 计算本年度的第几天
def count_day(y, m, d):
today = d
if is_leap_year(y) == True:
lis = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30]
else:
lis = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30]
for i in range(m):
today += lis[i]
print('今天是该年份的第{}天。'.format(today))
count_day(year, month, day)