Lesson 8 of 26 · about 15 min
Meet Bit the robot
Control a robot on a grid with a handful of commands. Sequences, loops and decisions turn a few simple commands into smart behavior.
🧭 What you need first: for loops and range
Meet Bit, a small robot that lives on a grid. Bit is very obedient and not at all clever. It understands exactly six commands, and it does nothing else.
Here’s the interesting part: with just those six commands, plus the loops and decisions you already know, Bit can solve surprisingly tricky puzzles. Real robots work the same way. A warehouse robot only knows things like “drive forward,” “turn,” “lift.” The intelligence is all in how the program combines them.
Another way: giving directions to a tourist
You can get a tourist anywhere in a city with just “walk straight,” “turn left,” “turn right,” and “is the road blocked?” The cleverness is in the order and the repetition, not in fancy commands.
Another way: LEGO
A LEGO set has only a few brick shapes, but you can build a castle. Simple commands are the bricks; your program is the castle.
Drive Bit around
Run this, then change it. Make Bit paint a little smiley, visit every corner, or crash into a wall on purpose to see what happens.
Bit can: move() turn_left() turn_right() paint(color) front_is_clear() get_color()
The real words
- Each of Bit’s abilities is a function. Writing
move()is a function call: the name, then brackets, meaning “do it now.” Some functions take an argument inside the brackets, like the color inpaint("red"). - Some functions give back an answer:
front_is_clear()returnsTrueorFalse, so you can use it as a condition. - Control flow is the order in which lines run. You have three tools:
- Sequence: run lines top to bottom.
- Repetition:
forandwhileloops. - Selection:
if/elif/else.
Computer scientists proved long ago that these three are enough to express any computation. Everything else is convenience.
General vs. specific solutions: “move, move, move, move” works for a world exactly 5 squares wide. while front_is_clear(): move() works for every width. Good programs solve the general problem.
Paint the whole road
Paint every square of the road red, including the first and the last. Use a while loop so it would work on a road of any length.
Bit can: move() turn_left() turn_right() paint(color) front_is_clear() get_color()
Jump the hurdle
A wall blocks the bottom row. Get Bit to the dashed square on the bottom right, facing right.
Bit can: move() turn_left() turn_right() paint(color) front_is_clear() get_color()
Why is while front_is_clear(): move() better than writing move() four times?
Got it?
Finish the lesson to color it in on your map and collect its concept cards.
Did this lesson click?