Skip to main content
Module 2 · Line Tracking

Lesson 2-7 · Finishing the Sensor Toolkit — Knowledge Checks

Name Date
  1. Why can get_left() use reflectance when it was never passed in as a parameter?

    1. A.Python passes the first variable in the file automatically
    2. B.reflectance is a global variable — created outside every function, so every function below it can read it
    3. C.get_left() creates its own reflectance each call
    4. D.It cannot; this is a bug

    Answer Why?

  2. Which condition detects an intersection (both sensors on the line)?

    1. A.left > 0.5 or right > 0.5
    2. B.left > 0.5 and right > 0.5
    3. C.left > 0.5
    4. D.not (left > 0.5)

    Answer Why?

  3. Both sensors read 0.2 with THRESHOLD = 0.5. What do is_at_cross() and is_either_on_line() return?

    1. A.True and True
    2. B.False and False — neither reading is above the threshold, so neither the and nor the or is satisfied
    3. C.False and True
    4. D.True and False

    Answer Why?

  4. Why does get_error() call get_left() instead of reflectance.get_left()?

    1. A.reflectance.get_left() is slower
    2. B.So only one function knows how the hardware is read — if the sensor changes, you fix get_left() and everything else keeps working
    3. C.Functions cannot use global variables twice
    4. D.It makes no difference either way

    Answer Why?

  5. Why does set_threshold() need the global keyword when is_at_cross() does not?

    1. A.Because set_threshold takes a parameter
    2. B.is_at_cross() only reads THRESHOLD; set_threshold() assigns to it, and without global the assignment makes a throwaway local variable instead
    3. C.Every function that mentions THRESHOLD needs global
    4. D.Because THRESHOLD is in capitals

    Answer Why?