Below are two MCQs relating to the Creating Functions in python from this lesson.
(The following questions assume python version 2.7 or below)
def compute_slope(y=0, x, b=0):
"""calculate the slope, m, in the equation y = mx + b"""
m = (y - b) / x
return m
- The function above was written to solve for the slope of a straight line. There is at least one problem, identify its location.
- issue in the parameter names of the function
- issue in the function body
- issue in the return value
- 1 and 3
- 2 and 3
- 1 and 2
- The statement 66/10 will produce the same answer as
- 66 % 10
- 61 / 10
- 69 // 10
- all of the above
- none of the above
Correct answer: E
The example of debugging a function is a lesson in integer math. This MCQ tests this understanding further. Each of the distractors is meant to test understanding of: A: modulo (or remainder) B, C: how rounding occurs in integer division (floor) C: how integer division can be clearly (intentionally) stated