Skip to main content
Module 2 · Line Tracking

Lesson 8 · Introduction to Classes — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. What's the difference between a class and an object?

    1. A.They are two words for the same thing
    2. B.A class is the blueprint; an object is a specific thing built from it
    3. C.A class is smaller than an object
    4. D.An object is only for sensors

    One class (blueprint) can produce many objects (instances). LineSensor is the blueprint; the sensor you create from it is an object.

  2. When does the __init__ method run?

    1. A.When you import the file
    2. B.When you create an object with LineSensor()
    3. C.Every time you call any method
    4. D.At the end of the program

    __init__ is the constructor — Python calls it automatically the moment you build a new object with LineSensor().

  3. You have `sensor = LineSensor()`. How do you call its get_error method?

    1. A.sensor.get_error(self)
    2. B.sensor.get_error()
    3. C.get_error(sensor)
    4. D.LineSensor.get_error()

    You never pass self yourself — Python supplies it automatically. Just sensor.get_error().

  4. Write is_on_line() to return True when AT LEAST ONE sensor is on the line. Which body is correct?

    1. A.return self.get_left() > self.threshold or self.get_right() > self.threshold
    2. B.return self.get_left() > self.threshold and self.get_right() > self.threshold
    3. C.return get_left() or get_right()
    4. D.return self.threshold

    'At least one' means or, and each reading needs self. — self.get_left() > self.threshold or self.get_right() > self.threshold.