Skip to main content
Module 1 · Learning to Drive

Lesson 1-8 · Hello, Python — Knowledge ChecksAnswer key

Correct answers are marked and the explanation follows each question.

  1. What's the main advantage of a general-purpose language like Python over Blockly?

    1. A.Python programs always run faster
    2. B.It isn't limited to the blocks someone built, and it opens up libraries other people have already written and tested✓
    3. C.Python makes it impossible to write a program with mistakes in it
    4. D.Blockly cannot do loops or functions

    Blockly gave you the ideas, and it can do loops and functions perfectly well. What it can't do is go beyond the blocks provided, or reach the huge collection of ready-made Python libraries you can build on as programs get more complex.

  2. A program starts with "from XRPLib.rangefinder import Rangefinder" and then calls rangefinder.distance(). It fails with a NameError. What was skipped?

    1. A.Step 2 — no instance was made, so the name rangefinder means nothing yet✓
    2. B.Step 1 — the import line is wrong
    3. C.The program needs to import Rangefinder twice
    4. D.Nothing — distance() only works in Blockly

    Importing the class makes Rangefinder available; it does not create rangefinder. The middle step — rangefinder = Rangefinder.get_default_rangefinder() — is what gives that name an object to stand for the hardware.

  3. Where do the three steps actually go in a real program?

    1. A.Steps 1 and 2 go near the top and run once; step 3 goes wherever the program needs that device, as often as it likes✓
    2. B.All three must be written together, in that order, every time
    3. C.Step 2 has to be repeated before each use of the device
    4. D.They can go in any order as long as all three are present

    Setup happens once: one import, one instance. Using the device is the actual program — it can be twenty lines later, inside a loop, or inside a function, and it happens as many times as you need. The three-line examples are squashed together only to show the shape.

  4. Which line is written correctly?

    1. A.Print("Driving...")
    2. B.print "Driving..."
    3. C.print("Driving...")✓
    4. D.print(Driving...)

    Lowercase print, parentheses around the call, and quotes around the text. The others break one rule each.

  5. What do the parentheses in board.wait_for_button() do?

    1. A.They tell Python to call the function — and anything inside them is an argument passed to it✓
    2. B.They are decoration; Python ignores them
    3. C.They mean the function returns nothing
    4. D.They are only needed when there is something inside them

    Parentheses are what turns a name into a call. wait_for_button needs no arguments, so they're empty — but leave them off and Python just names the function without running it.

  6. Why does drivetrain.straight(-30) drive the robot backward?

    1. A.Negative numbers reverse the direction — same as a negative cm in the Straight block✓
    2. B.It drives forward 30 cm, then stops
    3. C.It turns instead of driving
    4. D.It causes an error

    A negative distance means backward, exactly like typing a negative cm value into the block.

  7. Find the bug in the code above.

    1. A.straight should be capitalized
    2. B.Print should be lowercase: print✓
    3. C.The distances should be positive
    4. D.There is no bug

    Python is case-sensitive. Print with a capital P isn't the same as the built-in print.