任务:给出年月日,确定它是该年的第几天
year = int(input('年份:'))
month = int(input('月份:'))
day = int(input('日期:'))
days = 0
run = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
bu_run = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
# print('%d年是闰年' % year)
for i in range(month - 1):
days += run[i]
else:
# print('%d年是平年' % year)
for i in range(month - 1):
days += bu_run[i]
days += day
print('{} 年 {} 月 {} 日 是 {} 年的第 {} 天'.format(year, month, day, year, days))
输出结果:
年份:2020
月份:12
日期:25
2020 年 12 月 25 日 是 2020 年的第 360 天