2
Find the mistake
Computing 2: Unit 8, pp. 106–121
GoalTrace a drawing algorithm to find a bug and fix it.
New words
bug · a mistake in an algorithm or a programtrace · to follow the steps one by one to see what they dofix · to change something so that it is right
Explanation
An algorithm for a drawing can have a bug. The robot then draws a different shape. To find the bug, trace the algorithm one step at a time with a pencil. Stop when the path stops matching the picture that you wanted. The step you just traced is the bug. Fix it and trace again from the start.
Worked examples
This algorithm should draw the number 2, but one turn is wrong. The picture shows what the robot draws. After the second line the robot should turn right, but step 6 says turn left. The robot walks away from the 2.
| Step | Wrong | Right |
|---|---|---|
| 6 | Turn left | Turn right |
A wrong number is also a bug. A lamp post should be forward 5, turn right, forward 2. The robot starts at the bottom left, facing up. If step 3 says forward 4, the post is one square too short. The star shows where it should end.
Class activity
Bug hunt for robots: an adult writes an algorithm for a simple shape on paper but changes one turn or one number. You trace it with a pencil on squared paper. Where does your path stop matching the shape? Which step is the bug? Fix it. Then make a bug for your adult to find.
Practice
1
This algorithm should draw a U with arms of 3 steps: start, marker down, forward 3, turn left, forward 2, turn left, forward 2, stop. Which step has the bug and what must it be?
Step 7. Forward 2 must be forward 3.
2
An algorithm for the number 7 says: start, marker down, forward 2, forward 4, stop. The robot draws a straight line. What is missing?
A turn right between forward 2 and forward 4.
3
How can you find a bug in a drawing algorithm?
Trace it one step at a time and compare the path with the picture you wanted. The first step that goes wrong is the bug.
4
A partner reads the steps aloud while you trace. Why does this help?
Two people notice more, and reading aloud helps you keep your place.