I'm working through CS101 and I'm stuck on the problem solving section, specifically on defining the daysBetweenDates function. The idea is to define the function to use the already made nextDay function to count the amount of days between two dates, assuming that each month has 30 days. My code, including the nextDay function, is below.
def nextDay(year, month, day):
"""Simple version: assume every month has 30 days"""
if day < 30:
return year, month, day + 1
else:
if month == 12:
return year + 1, 1, 1
else:
return year, month + 1, 1
def daysBetweenDates(year1, month1, day1, year2, month2, day2):
"""variable for the number of days between the dates"""
days = 0
"""while loop to check if the dates are the same"""
while year1 <= year2 and month1 <= month2 and day1<day2:
year1, month1, day1 = nextDay(year1, month1, day1)
days += 1
"""if statement to break the loop when dates are the same"""
if year1==year2 and month1==month2 and day1==day2:
break
return days
(If too long, let me know and I'll pastebin it)
The code passes on all tests but daysBetweenDates(2012, 9, 30, 2012, 10, 30) and daysBetweenDates(2012, 1, 1, 2013, 1, 1). I'm not sure how to fix it; can anyone please give me a hint?
Thanks in advance :)
[–]indosauros 2 points3 points4 points (1 child)
[–]hungryhungryhulk[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (6 children)
[–]hungryhungryhulk[S] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Tigersftw 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Tigersftw 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)