# Define a daysBetweenDates procedure that would produce the # correct output if there was a correct nextDay procedure. # # Note that this will NOT produce correct outputs yet, since # our nextDay procedure assumes all months have 30 days # (hence a year is 360 days, instead of 365). # 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): """Returns the number of days between year1/month1/day1 and year2/month2/day2. Assumes inputs are valid dates in Gregorian calendar, and the first date is not after the second.""" # YOUR CODE HERE! Total_Days = 0 while (year1, month1, day1) != (year2, month2, day2): year1, month1, day1 = nextDay(year1, month1, day1) Total_Days = Total_Days + 1 return def test(): test_cases = [((2012,9,30,2012,10,30),30), ((2012,1,1,2013,1,1),360), ((2012,9,1,2012,9,4),3)] for (args, answer) in test_cases: result = daysBetweenDates(*args) if result != answer: print "Test with data:", args, "failed" else: print "Test case passed!" test()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question