Lesson 4 · Module 3 Final Project
Lesson 4 · Module 3 Final Project
Teacher mode is on. Toggle it off (bottom-right) to preview the student view.
Time to tie the module together. Your robot will drive a complete square on the
grid — two intersections per side, turn right at each corner, four times — and end
up right back where it started. Same LineTrack class, no new Python: just your
tools, put to work.
Learning Objectives
By the end of this project you will be able to:
- Design a program that drives a closed square path on the grid
- Use a
forloop to repeat a drive-and-turn sequence - Test and tune a real robot until the path closes
- Verify the robot returns to its starting position
The mission
Make the robot drive a square: each side is 2 intersections, with a right turn at each of the 4 corners. Done right, it finishes where it began.
Your program must: use the LineTrack class, drive the square with a for loop
(not four copied blocks), print progress, and return to start.
One loop, four sides
The whole square is a four-iteration loop: each pass drives one side, then turns the
corner. Two pieces to write — a drive_intersections(tracker, count) helper (you
built this in Lesson 2) and the loop that calls it and turns.
Sketch the loop body in English first: what happens once per side?
Notice there's no separate clear before turn_right() — the turn clears the corner
itself (Lesson 3). Four right turns add up to a full 360°, which is why the robot
comes back around.
The square loop runs turn_right() once per side, four times. How many total degrees does the robot turn?
Activity · Test one side at a time
Don't run all four sides first. Build up:
- One side — comment out the loop; run one
drive_intersections(2)+turn_right(). - Two sides —
range(2). What shape should that give you? Predict, then run. - Full square —
range(4); does it close back to the start?
A student wrote `for leg in range(3):` and added a clear step right before turn_right(). What are the two bugs?
Activity · Extend it
Once the square works, try a variation:
3-per-side square
Set sides = 3 for a larger square. Does it still close?
Alternating legs
Use a list [2, 3, 2, 3] and index it by leg so opposite sides differ.
Left-turn square
Swap in turn_left() to drive the square the other way around.
Activity · Reflect
Demo your square and think back:
- What was hardest to get working, and how did you fix it?
- Why is the
forloop better than copying the side code four times? - How is this different from the polygon function in Module 1? (There you set distances and angles; here you count intersections and follow real lines.)
Nice work — Module 3 done 🎉
You reused a class you wrote weeks ago on a brand-new surface, learned to clear intersections and count segments, and sequenced drives and turns into real paths. Every route here was one you planned and hard-coded. That's about to change.