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 | |
|---|---|---|
| 1"""Return the area of a rectangle.""" | ADisplays the docstring of the calculate_area function | |
| 2help(calculate_area) | BA docstring: a triple-quoted string on the first line of a function body that says what the function does | |
| 3A docstring describes each parameter and the return value so other programmers know what to pass in and what comes back | Cclass Student: """A student with a name and a mark.""" | |
| 4A class docstring goes on the first line inside the class body and describes what the class represents | DSingle quotes were used for a multi-line docstring, which causes a syntax error. Use triple quotes at the start and end. | |
| 5def total(a, b): x = a + b """Add two numbers.""" return x | EThe docstring is not on the first line of the function body, so Python does not treat it as the docstring and help() will not show it. Move it above x = a + b. | |
| 6def total(a, b): "Add two numbers. Returns the sum." return a + b | F"""Add GST to a price. price: float, the cost before GST Returns: float, the cost with GST """ |
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 on the first line of a function or class body. It documents what the code does, its parameters and its return value. help() displays it.class Student:
"""A student record."""
help(Student)def area(w, h):
"""Return the area."""
help(area)def area(w, h):
"""Return area. :param w: the width"""
return w * hclass Student:
"""A student record."""
count = 0def area(w, h):
"""Find area. :return: the area"""
return w * h