A201

Practice and Review

Practice questions and problems, and review material such as test solutions, appear below (most recent first). This is not used in the Alice part of the course.


Apr 23: Week 15 practice and review problems

Apr 14: Week 14 practice and review problems

Apr 07: Week 13 practice and review problems

Mar 31: Week 12 practice and review problems

Mar 26: Week 11 practice and review problems

Mar 18: Week 10 practice and review problems

Mar 04: Week 9 practice and review problems

Feb 26: Week 8 practice and review problems

Feb 20: Week 7 practice and review problems

Feb 12: Week 6 practice and review problems

Feb 05: Week 5 practice and review problems

Jan 31: Week 4 practice and review problems

Some weeks the problems are in plain text files, with answers posted in the Resources tool of the course Oncourse site. Others are HTML pages that allow you to test your knowledge by filling in forms using Mozilla Firefox (on the STC machine start menu and a free download). Javascript must be enabled. Unfortunately the standard web mechanism that supports this does not work in some other browsers, including Internet Explorer. Sorry for the inconvenience.

Round radio buttons indicate multiple-choices with one correct answer, square check boxes indicate you should select all correct responses, text boxes are for on-line answers, and text areas are for multi-line answers. Then check your answers by hovering the mouse over the blue Answer elements. Do yourself a big favor and never check an answer until you have made your best effort to answer the question, looking up material in the text or class notes if necessary. You are wasting an opportunity if you just look at the answers and think "yeh, I knew that" or "I know that now".with form elements that allow you to

Starting in week 5, comments with horizontal and vertical sequences of dots, called ellipses, will often appears in questions, both on HTML and plain text files linked from this page, in class presentations, and on tests. Whenever you see an ellipsis in a question, you are to play a "replace the dots" game. Specifically:

  • If a line contains a horizontal ellipsis comment "#..." you are to replace it with any number of characters on the same line.
  • If there is a vertical ellipsis (two or more lines containing nothing but "#." comments that align vertically), replace the lines with appropriate text. This is as if each line had a horizontal ellipsis on it, except that you may replace them with more or fewer text lines than there are dot lines (though one possible answer will use the indicated number of lines).
  • If replacement text is part of Python code, its behavior should be consistent with the ellipsis context. The context includes all output, comments, and documentation strings.
  • If replacement text is in the position of some output, indicate exactly what the output would be, unless the output at that point would be an error message, in which case just indicate whether it is a syntax error or runtime error. (Though debugging requires that you learn how to interpret error messages, you will never be asked to predict details of an error message other than whether it is a syntax or runtime error.)

For example, given the ellipsis question

>>> 1 + 2 * 3
#...
>>> print 'a\nb'
#.
#.
>>> ... math
>>> math.sqrt(4)
2.0
>>> 3 = 4
#...
>>> x
#.
#.
>>> def sum(a, b):
        "Return the arithmetic sum of a and b."
        #...
the correct response (with bold ellipsis replacement text) would be
>>> 1 + 2 * 3
7
>>> print 'a\nb'
a
b
>>> import math
>>> math.sqrt(4)
2.0
>>> 3 = 4
Syntax error
>>> x
Runtime error

>>> def sum(a, b):
        "Return the arithmetic sum of a and b."
        return a + b
The runtime error is because a variable named x is not defined. Unless otherwise indicated, assume no prior definitions other than built-in functions.