Python活力练习Day1

Day1:输入年月日,判断这一天是这一年的第几天

    eg:    input : 2019-02-01

         output : 32

data = list(input('please input year,month,day:').split('-'))
data = [int(x) for x in data]
Month = [31,28,31,30,31,30,31,31,30,31,30,31]
i = 0
total = data[2]
while i < data[1] - 1:
    total += Month[i]
    i += 1
if data[0] % 400 == 0 or (data[0] % 4 == 0 and data[0] % 400 != 0):
    if data[1] > 2:
        total += 1
print('it is the %dth day in the {} year.'.format(data[0])%total)

 

你可能感兴趣的:(Python)