Skip to main content
Module 1 · Learning to Drive

Lesson 9 · Python Loops — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. What numbers does range(4) produce?

    1. A.1, 2, 3, 4
    2. B.0, 1, 2, 3
    3. C.0, 1, 2, 3, 4
    4. D.4, 3, 2, 1

    range(n) counts from 0 and stops BEFORE n, so range(4) is 0, 1, 2, 3 — four numbers, which is why the loop runs 4 times.

  2. In the code above, how many times does print("Square complete!") run?

    1. A.Four times — once per loop
    2. B.Once, after the loop finishes
    3. C.Never
    4. D.It causes an error

    Because it isn't indented, print is outside the loop body — it runs a single time once the loop is done.

  3. You want a loop to run 6 times to draw a hexagon. What goes in the range?

    1. A.range(5)
    2. B.range(6)
    3. C.range(7)
    4. D.range(60)

    range(6) gives 0–5, which is six passes — one per side of the hexagon (turning 360 ÷ 6 = 60° each time).

  4. In the nested program above, how many times does drivetrain.straight() run in total?

    1. A.Four times — once per square
    2. B.Sixteen times — four sides in each of four squares
    3. C.Eight times
    4. D.Once, because it is inside two loops

    The inner loop runs four times per pass of the outer loop, and the outer loop runs four times: 4 × 4 = 16 sides.

  5. What happens if you indent the size line twice, so it lines up with the drivetrain lines?

    1. A.Nothing changes
    2. B.The program will not run at all
    3. C.Every square comes out the same size
    4. D.The robot draws only one square

    It still computes the same value, just four times per square instead of once — wasteful, but harmless. Indentation changes WHEN a line runs; here the answer happens to be the same either way. (Move it ABOVE the outer loop, though, and every square really would come out the same size.)