Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1def area(w, h): """Return the area of a rectangle.""" | AThe docstring uses single double quotes instead of triple quotes. Docstrings should use triple quotes, as in """text""". | |
| 2class Student: """A student with a name and a mark.""" | Bdef add(a, b): """Add two numbers. a, b: numbers to add Returns: their sum""" | |
| 3A function docstring can list the parameters and the return value so other programmers know how to use it | Cclass Dog: """A pet dog with a name and age.""" | |
| 4A docstring is written with triple quotes as the first statement inside the function or class body | DThe docstring is not the first statement in the function. It must come straight after the def line, before any other code. | |
| 5def area(w, h): x = w * h """Return the area.""" return x | EA class docstring: a triple-quoted string on the first line inside the class that describes what the class represents | |
| 6class Car: "A car with a make and a speed." def __init__(self, make): | FA function docstring: a triple-quoted string on the first line inside the function that describes what it does and returns |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
"""docstring""" — A triple-quoted string placed first in a function or class that describes its purpose, parameters and return value. It is internal documentation.def area(w, h):
"""Return the area of a rectangle."""
return w * hclass Player:
"""A player in the game."""
lives = 3def area(w, h):
"""Return the area of a rectangle."""
return w * hclass Dog:
"""A pet dog with a name."""
def bark(self):def area(w, h):
"""Return the area of a rectangle."""
print(area.__doc__)