AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Write it, fix it

Week 20 · Unit 8: Be an artist · 3 lessons
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.

trace step by stepstop at the mismatchfix and trace again
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.
StepWrongRight
6Turn leftTurn right
The fix: change step 6 from “turn left” to “turn right”. Then trace the whole algorithm again.
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?
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?
3
How can you find a bug in a drawing algorithm?
4
A partner reads the steps aloud while you trace. Why does this help?