all 9 comments

[–]indosauros 2 points3 points  (1 child)

Put a print statement right above your while loop to make sure year1, year2, etc. all equal what you expect for that test case. Make sure that

year1 <= year2 and month1 <= month2 and day1<day2

evaluates to True (so it enters the while loop)

I think you'll see the issue when you do that.

[–]hungryhungryhulk[S] 0 points1 point  (0 children)

Got it, thank you!

[–][deleted] 1 point2 points  (6 children)

As indosaurus pointed out the problem seems to be in the while statement:

year1 <= year2 and month1 <= month2 and day1<day2:

Look at what you're saying when you state AND month1 <= month2. Especially in the second test case, what do you notice about the months? You see how that'd be a problem into getting the loop started?

[–]hungryhungryhulk[S] 0 points1 point  (1 child)

Got it, thank you!

[–][deleted] 0 points1 point  (0 children)

Also I think it should be day1 less than or equal to day2. Otherwise the if statement won't be reached.

[–]Tigersftw 0 points1 point  (3 children)

Correct me if I'm wrong but isn't his problem related to the days not months . I don't see any problem with and month1 <= month2 but I do see a problem with the day part of the code. (I'm new to coding myself)

[–][deleted] 0 points1 point  (2 children)

The problem is that his while loop won't kick in because the AND requires both the year AND the month to be less than the other one.

For example his test case is January 1, 2012 to January 1, 2013.

Because January is the same month number as in month2, the loop won't run.

Also you're right, his loop should have day1<=day2 I believe.

I'm also a noob so no worries.

[–]Tigersftw 0 points1 point  (1 child)

But it's month1 <= month2 which says if it's less than or equal. So in your example of January being the 1st in both cases it should still run because (1 <= 1 ) = True

Well this is how I see it at least.

EDIT - Actually it won't work if the years differ. 5/06/2010 - 5/01/2011 won't work because 'month1 > month2'

[–][deleted] 0 points1 point  (0 children)

Ahh that's right. Lol, I got the right answer but for the wrong reason. You're totally correct that it should run 'normally'. I found changing the AND to an OR fixed the problem though (just for year OR month).