YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Define nextDay - Intro to Computer Science

Get Embed Code
3 Languages

Showing Revision 5 created 05/25/2016 by Udacity Robot.

  1. So, here's my solution to implementing nextDay and you'll note that I start with
  2. a docstring. This is treated as a special common by most Python systems and I
  3. put in this warning to make people realize this [unknown] is not actually
  4. correct. So, it shouldn't be used to schedule, say, the apocalypse, but it's
  5. good for our testing for now. And the logic is quite simple, if the day is less
  6. than 30, since we're assuming all months have 30 days, we increase the day by 1,
  7. and I'm returning a three tuple of the year, the month, and the day. Otherwise,
  8. we need to increase the month, so we're going to advance to the next month and
  9. reset the day to 1. If we're in December, then we need to increase the year by 1
  10. and reset the date to January 1st. As with the larger problem, you should start
  11. this by thinking about some test cases. And see that those behave as expected.
  12. We provided some in the example. One nice thing you'll notice here using the
  13. Python shell provided by [unknown] is that, when I try to use nextDay, I see the
  14. docstring right here. And normally, we want docstrings that are descriptive
  15. here. The warning is very useful. And I give a sample month, day, and year, and
  16. I see that I get the right result. I should note that for some cases, say,
  17. January 30th, the day following January 30th should be January 31st. I'm going
  18. to get February 2nd because of this assumption about all months having 30 days,
  19. and we should try a more difficult case, such as the end of the year. And here,
  20. I'll use December 31st, it would advance the year whether it's December 31st or
  21. December 30th because of that assumption, and we get January 1st, 2013.