# 输入年月日
year = int(input('year:'))
month = int(input('month:'))
day = int(input('day:'))
# 将正常情况下,每一个月的累计天数放入到元组中进行保存
months = (0,31,59,90,120,151,181,212,243,273,304,334)
if 0 < month <= 12:
# 如果输入的数据正确,月份在 1~12 之间
sum_days = months[month - 1]
# 总天数就为 列表中的天数,索引值根据 输入的月份进行选择
else:
print ('数据错误,请重新输入')
# 加上输入的日期
sum_days += day
# 默认不是闰年
leap = 0
# 判断是否是闰年,被 400 整除,可以整除4 但是不能被 100 除掉
if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)):
leap = 1
# 如果为 1 则表示 这一年是闰年
if (leap == 1) and (month > 2):
# 当这一年是闰年,并且月份大于 2 时,说明存在 29 日,所以总天数再增加 1
sum_days += 1
print ('这是 %d 年的第 %d 天.' % (year,sum_days))
2020-05-18