Sunday, June 9, 2013

A Frequently Asked Question on the Udacity CS101 Forum

On the Udacity CS101 Forum, I've been surprised at the number of questions that were posted for quiz 2-18. For example there's this question: and several many more that are much like it.

Now part of the confusion, I think is that when Python prints the string value "True" and prints the Boolean value True, there's no visible distinction between the 2 outputs. e.g.:

>>> print "True", True
True True

But I think it is perhaps worth noting that in the coursera course "Introduction to Systematic Program Design", there is strong emphasis in the course's "How to Design Functions" recipe on starting by writing down the function's "signature", the types of its inputs and of its outputs, which for quiz 2-18 would be:

# String -> Bool

(Mostly irrelevant is the detail that Udacity CS101 is working in Python 2.7 while the coursera course is working in "Dr. Ratchet", another programming language, and one that is new to me).

For as small a quiz as 2-18 is, and as often as similar questions have shown up in the forum, I think it is clear evidence that CS101 needs to add emphasis on function "signatures". It would also make sense to soup up the auto-grader for this problem to give more specific feedback if the function returns string values instead of the desired Boolean values.

For what it is worth, here's my answer to the question I cited in this article's opening paragraph.

I didn't actually run your code, but I see your function returns string values of "True" or "False". Python has special Boolean values of True and False (NB. no quotation marks). They behave in many ways like 1 and 0, but they are easier to read in the source code.

So, my best guess is that the autograder is looking for Boolean True and False, not the strings that you are handing to it. Further reading: Truthiness and Falsiness. By the way, the version of Python that CS101 is using has changed a little since I wrote that blog article last year. Also, be aware that None is another special value in Python.