Unit 4
Predict, run and fix
Work out what a block program will do, run it, and use the difference to find and fix the bug.
Read
Pip goes the wrong way
Mia built a program to take Pip the cat to the flag. She snapped the blocks together, tapped the green flag, and watched.
Pip walked right, right, then down, then right. Pip stopped two squares below the flag!
"Pip is silly!" said Mia.
But Pip did exactly what the blocks said. Let's find out what went wrong.
Predict, run, compare, fix
You have found bugs before. In a block program, you can find them with four steps.
- Predict. Before you run the program, work out what it will do. Use your finger to follow the blocks one at a time. Say where Pip will stop.
- Run. Press the flag and watch. Pip does each block, one after the other.
- Compare. Is what happened the same as what you wanted? Is it the same as your prediction?
- Fix. If it is different, there is a bug. Find the block that is wrong and change it. Then run it again.
A bug is a block, or a missing block, that makes a program do something different from what you meant.
Where is the bug?
Mia put what she wanted next to what happened.
The two paths are the same for blocks 1 and 2. They split at block 3. Mia wanted Pip to go up, but she used Down. That is the bug.
This is the big idea. When you compare what you wanted with what happened, the place where they first differ shows you where the bug is.
Example. Mia changes block 3 from Down to Up. Now the program is Right, Right, Up, Right.
- Predict: Pip goes right, right, up, right. Pip stops on the flag.
- Run: Pip stops on the flag.
- Compare: same! The bug is fixed.
Kinds of bugs
What you see The bug The fix Pip goes the wrong direction A wrong block Change the block Pip stops one square short A block is missing Add the block Pip goes one square too far There is an extra block Take the block away A repeat block does too few or too many The repeat number is wrong Change the number Pip bumps into a rock Blocks are in the wrong order Move the blocks Why predict first?
Suppose you only run the program and look. You might not notice that Pip went the wrong way, or you might not know which block did it. If you predicted first, you already have a picture of what should happen. Then the run shows you a difference you can see.
If your prediction was wrong, that is useful too! It means you did not follow the blocks exactly, and you have learned something about how the blocks work.
Things people get wrong
Pip is not broken. The tablet is not broken either. A computer does exactly what the blocks say. If the result is wrong, the blocks are the thing to look at.
Change one thing, then run again. If you change three blocks at once, you won't know which one helped.
The bug might be early. Everything Pip does after a wrong block can also look wrong, because Pip is in the wrong place. Look for the first block where the two paths differ.
For the grown-up helping
Ask your child to point at each block and say out loud where Pip will be after it, before pressing run. If the result is not what they wanted, ask "Where did it first go differently?" and let them find the block. Please resist fixing it for them. Finding the bug is the skill. It is normal to be wrong about the prediction at first.
Lab
The fix-it board
Each mission gives you a program with a bug. Predict where Pip will stop, run it, compare with the flag, work out what kind of bug it is, fix it and run it again. There are five missions.
Your goals
- Predict where a program will leave Pip before you run it.
- Compare what happened with where Pip should have gone, and say what kind of bug it is.
- Fix five different kinds of bug so that Pip reaches the flag.
The interactive lab opens once you register. Register to do this.
Activity
The bug swap
Your child and a grown-up swap block programs that each have a bug on purpose. They predict, run on a paper grid, compare, and fix. About 25 minutes.
You'll need
- Squared paper, or a 5 by 5 grid drawn on plain paper
- Pencils in two colours
- Small cards or sticky notes for blocks (Right, Left, Up, Down, Repeat), or just words written on paper
- A coin or button for Pip, and a small drawn flag
Steps
- Draw a grid with a start square and a flag square. Put Pip (the coin) on the start square.
- Each of you writes a program of 4 to 6 blocks to take Pip to the flag. Then each of you changes one block on purpose, so the program has a bug. Do not tell the other person which block.
- Swap programs. First, predict. Point at each block and say out loud where Pip will be after it. Mark where you think Pip will stop with a small pencil cross.
- Run it. Slide the coin along the grid, one square per block. Does it stop where you predicted? Does it reach the flag?
- Compare. Draw the path Pip took in one colour and the path you wanted in another colour. Where do the two paths first part? That block is the bug.
- Fix it. Change that one block, then predict again and run it again.
- Try a bug with a Repeat block. For example, a staircase with "Repeat 2 times (Right, Up)" when the flag needs 3 steps. Which number is wrong?
- Swap roles and play again with new programs. Ask your child "How did your prediction help you find the bug?"
Safety
- Use soft pencils and keep coins or buttons away from babies and toddlers.
Keeping a log of the activity is for registered learners. Register to do this.
Quick check
Fixing block programs check
Six questions about predicting, running and fixing.
1.What does it mean to predict what a program will do?
- Work out what it will do before you run it
- Run it and watch
- Fix a bug in it
- Add more blocks to it
Choose one
2.You predicted the cat would stop on the flag, but it stopped one square short. What is the best thing to do first?
- Compare what happened with what you wanted, to find where they first differ
- Throw the program away and start again
- Add lots of blocks at the end
- Decide the tablet is broken
Choose one
3.The cat should end on the flag. The program is Start, Right, Right, Down, Right. Which block number is the bug? (Block 1 is the first Right.)
Answer with a number
4.The cat should walk to the flag. What number goes in the blank: Repeat ___ times (Right)?
Answer with a number
5.The flag is 3 squares to the right of the cat. The program is Right, Right, Right, Right, and the cat goes one square too far. Which changes would fix it? Pick all that apply.
- Take one Right block away
- Replace the program with Repeat 3 times (Right)
- Add another Right block
- Change one Right block to Left
Choose all that apply
6.Put the steps of fixing a program in order.
- Run the program and watch
- Fix the block that is wrong
- Run it again
- Predict what the program will do
- Compare what happened with what you wanted
Put these in order
Answering and checking are for registered learners. Register to do this.
Quick check
New puzzles
Predicting and fixing work for lots of programs, not just Pip. Try these new ones.
1.Zoya's drawing robot has this program to draw a square: Forward, Turn, Forward, Turn, Forward, Turn. It draws only three sides. What should Zoya do?
- Add one more Forward block at the end
- Take away one Turn block
- Change the first Turn into a Forward
- Nothing, three sides make a square
Choose one
2.Pip starts at the bottom left. The program is Repeat 3 times (Right, Up). Pip should end 4 squares to the right and 4 squares up. What should the repeat number be?
Answer with a number
3.A friend says "My program is wrong because the tablet is broken." What is the best reply?
- The tablet did exactly what the blocks said. Compare what you expected with what happened to find the block that is different.
- Yes, you need a new tablet.
- Wait a day and it will fix itself.
- Delete all the blocks and use a different game.
Choose one
4.Pip starts in the bottom-left square of a big grid. The program is Right, Right, Up, Up, Left. After the program runs, how many squares to the right of its start is Pip?
Answer with a number
Answering and checking are for registered learners. Register to do this.
Activity
Tell it back
Your child explains, in their own words, how comparing a prediction with what happens shows where the bug is. Three minutes.
Steps
- Put a program on the table with a bug in it, for example Right, Right, Down, Right when the flag is up and to the right. Ask "Where will Pip stop? Where should it stop?"
- Ask "How can you find which block is wrong?" Let your child answer and show you on the program.
- Ask "Why is it a good idea to predict before you run it?"
- Write down what your child says in their own words. Do not correct it. If they get stuck, walk the program together one block at a time and ask again.
Keeping a log of the activity is for registered learners. Register to do this.
Like what you see?
Register for free to answer the quick checks, do the activities and save your work. Your work is saved on your device and syncs to your account.