题解 | #计算日期到天数转换#
计算日期到天数转换
http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded
一个简单,优美的代码实现如下:
date = input().split(' ')
year = int(date[0])
month = int(date[1])
day = int(date[2])
day_list = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0) :
day_list[2] += 1 # 闰年
sum_day = 0
for i in range(month):
sum_day += day_list[i]
sum_day += day
print(sum_day)