Skip to main content
Module 2 · Line Tracking

Lesson 9 · Object Composition — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. What does 'object composition' mean?

    1. A.Writing all your code in one giant class
    2. B.One class storing an instance of another class and using it
    3. C.Two classes with the same methods
    4. D.Turning a function into a class

    Composition is a 'has-a' relationship: LineTrack has-a LineSensor. It keeps each class focused on one job.

  2. Why is there a time.sleep(0.5) at the start of turn_right(), before the while loop?

    1. A.To let the motors warm up
    2. B.So the robot rotates off the cross first — otherwise the sensor is still on the line and the turn ends immediately
    3. C.To slow the whole program down
    4. D.It is required by every method

    Right after starting the spin, the sensors are still on the intersection. The pause lets the robot clear it before it starts looking for the next line.

  3. What does the `pass` inside the while loop do?

    1. A.Stops the loop
    2. B.Nothing — the loop just keeps re-checking the condition while the motors spin
    3. C.Passes control to another method
    4. D.Reads the sensor

    pass is a do-nothing placeholder. The motors were already told to spin; the loop simply waits, re-checking is_off_line() until a line appears.

  4. Why can the main program be just a few method calls now?

    1. A.The robot got faster
    2. B.All the sensor and motor detail is hidden inside the classes
    3. C.Classes make code run with fewer steps
    4. D.It skips the control loop

    Composition hides complexity: the classes hold the detail, so the main program reads as a clear sequence of intentions.