从输入的日期(如2008年12月12日)判断当前日期是当年的第几天
程序如下
1 r=0 #代表当年的第几天
2 year=int(input('please enter the year:'))
3 while True:
4 month=int(input('please enter the month:'))
5 if month<1 or month >12:
6 print('the month does not exist. Please reenter it')
7 else:
8 break
9
10 while True:
11 day=int(input('please enter the day:'))
12 if day<1 or day>30:
13 print('the day does not exit,Please reenter it')
14 else:
15 break
16
17 print('您选择的日期是:%s年%s月%s日'%(year,month,day))
18 a=[31,28,31,30,31,30,31,31,30,31,30,31]
19
20
21 if (year%4==0 and year%100!=0) or year%400==0:
22 a[1]=29
23
24 for i in range(0,12):
25 if month>=i+2:
26 r+=a[i]
27 else:
28 month==0
29
30 r+=day
31 print(r)
32 print('日期%s年%s月%s日是当年的第%s天'%(year,month,day,r))