### Udacity lesson 2.5, nextDay ### ### Define a simple nextDay procedure, that assumes ### every month has 30 days. ### ### For example: ### nextDay(1999, 12, 30) => (2000, 1, 1) ### nextDay(2013, 1, 30) => (2013, 2, 1) ### nextDay(2012, 12, 30) => (2013, 1, 1) (even though December really has 31 days) ### def my_function(year, month, day): day = day + 1 if day < 30 else 1 if day == 1: if month == 12: month = 1 else: month = month + 1 year = year + 1 if month == 1 and day == 1 else year return (year, month, day) def test(): test_cases = [ ((1,1,1), (1,1,2)), ((1999,12,1), (1999,12,2)), ((1999,12,29), (1999,12,30)), ((1999,12,30), (2000,1,1)), ((1999,1,30), (1999,2,1)) ] passes = 0 for (args, expected_result) in test_cases: result = my_function(*args) if result != expected_result: print "Failed when argument was: ", args, ". Expected: ", expected_result, " Got: ", result else: passes = passes + 1 print passes, " out of ", len(test_cases), " test cases 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