欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python活力练习Day1

程序员文章站 2024-02-01 11:06:22
Day1:输入年月日,判断这一天是这一年的第几天 eg: input : 2019-02-01 output : 32 1 data = list(input('please input year,month,day:').split('-')) 2 data = [int(x) for x in ......

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

    eg:    input : 2019-02-01

         output : 32

 

 

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