The Expected Output – Intro to Computer Science

The answers are, for the first one, the dates are the same. We said that was okay. The requirement is that the second date cannot be before the first date. It’s fine if they’re the same. And then the answer should be 0, there are no dates, between those two. The second one, the second input is one day after the first input, so the output should be 1. For the third one, the second date is before the first date. The way we specify the problem. That’s an invalid input. That means the output is undefined. And, our procedure could actually be correct, no matter what it does for this input. It’d be more useful if it gives a clear error message or maybe even more useful if it gives negative 1. But the way we specify the problem, we don’t have to worry about what the output is there, because we’re saying that these inputs are invalid. For the fourth one, the dates are a year apart, June 29 in 2013 is one year after June 29 in 2012. And so, there are 365 days in a non-leap year. And it’s non-leap year because the February that’s included is the February in 2013. For the final one, we’re going from June 29, 2012 to June 31st, 2013. If you know your calendar well, you know there’s actually no June 31st. The way we specified the problem, we said that both input dates have to be valid dates in the Gregorian calendar. That means that the output here is undefined. We’d like to get some kind of error output, but there’s no requirement for our procedure.

Tags: , , , , , , ,


  • figolu101 says:

    The last question's answer (undefined because June is not a 31 days' month) clearly reveals a bug in the Leap Year Baby exercice !
    Clearly, there (https://classroom.udacity.com/courses/cs101/lessons/48689154/concepts/6986185960923) we have such an incoherent date in an workout example, outputting nonetheless a valid answer !!!
    Look at the workout example there : output(is_leap_baby(29, 2, 1900), 'Charlie Brown')
    29-02-1900 can't exist (because of the rules of leap years !!!)

  • Mohammad Fadhil says:

    The last question is a trick question, c'mon Udacity.

Leave a Reply

Your email address will not be published. Required fields are marked *