The code is as follows
1 defLeap_year (y):#determine if a leap year2 if(y% 4 = = 0 andY% 100 = 0)orY% 400 = =0:3 returnTrue4 Else:5 returnFalse6 7 defDays_in_month (Y, m):#Judging every month for a few days8 ifMinch[1, 3, 5, 7, 8, 10, 12]:9 return31Ten elifMinch[4, 6, 9, 11]: One return30 A Else: - ifleap_year (y): - return29 the Else: - return28 - - defDays_this_year (year):#Judging a few days this year + ifleap_year (year): - return366 + Else: A return365 at - defDays_passed (year, Month, day):#Judging how many days have gone by this year -m = 1 -Days =0 - whileM <Month: -Days + =Days_in_month (year, m) inM + = 1 - returnDays + Day to + defdaysbetweendates (year1, Month1, Day1, Year2, Month2, day2): - ## the #Your code here. * ## $ ifYear1 = =year2:Panax Notoginseng returnDays_passed (Year2, Month2, Day2)-days_passed (year1, Month1, Day1) - Else: theSUM1 =0 +Y1 =year1 A whileY1 <year2: theSum1 + =days_this_year (y1) +Y1 + = 1 - returnSum1-days_passed (year1,month1,day1) +days_passed (year2,month2,day2)
Use the following code for correctness testing
defTest (): Test_cases= [((2012,1,1,2012,2,28), 58), ((2012,1,1,2012,3,1), 60), ((2011,6,30,2012,6,30), 366), ((2011,1,1,2012,8,8), 585 ), ((1900,1,1,1999,12,31), 36523)] for(args, answer)inchTest_cases:result= Daysbetweendates (*args)ifResult! =Answer:Print "Test with data:", args,"failed" Else: Print "Test Case passed!"Test ()
The test results are as follows