Year 7 · Spring 2
Scratch I: Programming essentials · Lesson 5 of 5
Debugging with PRIMM
PracticalTopic 11 Algorithms
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
You will learn to
- Use PRIMM to read a script: predict what it does before running it.
- Identify the block where a buggy script first goes wrong.
- Fix a bug, test it again, and explain the fix in one sentence.
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Success criteria
You have got it when you can say:
- I can write my prediction down before I click the green flag.
- I can find and fix the bug in three buggy scripts.
- I can explain each fix in one clear sentence.
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Retrieval starter
Questions from before. Write your answers, then show them.
- Last lesson
In a flowchart, a decision is a…
A DiamondB OvalC Rectangle
A. Diamond
- Last unit
Every spreadsheet formula starts with…
A #B =C $
B. =
- Earlier this year
A fake bank email asking you to log in is…
A PhishingB Brute forceC A worm
A. Phishing
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Key words (1 of 2)
- Algorithm
- Precise, ordered, finite steps to solve a problem.
- Decomposition
- Breaking a problem into smaller ones.
- Abstraction
- Ignoring detail that doesn't matter for the problem.
- Sequence · selection · iteration
- Steps one after another. First this, then this.
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Key words (2 of 2)
- Pseudocode
- Code-like writing for algorithms, without strict rules.
- Trace table
- Records variable values step by step to check logic.
- Variable
- A named place in memory that holds a value.
The explanation · step 1 of 4
Bugs are normal
A bug is a mistake in a program that makes it do the wrong thing.
Debugging means finding bugs and fixing them.
Every programmer writes bugs. Good programmers find them calmly, one step at a time.
Scratch blocks only snap together where they fit. So most Scratch bugs are logic errors: the script runs, but does the wrong thing.
The explanation · step 2 of 4 · part 1 of 2
PRIMM: a way to read code
PRIMM is five steps for working with a program someone else wrote.
| Letter | Step | What you do |
|---|---|---|
| P | Predict | Read the code. Say what you think it will do, before you run it. |
| R | Run | Run it and watch. Was your prediction right? |
| I | Investigate | Look closely. Trace it block by block. Change one thing and see what happens. |
| M | Modify | Change the code so it does something new. |
| M | Make | Write your own program using the same idea. |
The explanation · step 2 of 4 · part 2 of 2
PRIMM: a way to read code (continued)
Why predict first?
A wrong prediction is useful. The place where the code surprises you is where to look for the bug.
The explanation · step 3 of 4 · part 1 of 2
Debugging step by step
- Predict: what should the script do?
- Run it.
- Compare: what did it really do? Where is it different?
- Find the first block where it goes wrong.
- Fix one thing at a time.
- Run it again to check the fix works.
- Explain the fix in one sentence.
The explanation · step 3 of 4 · part 2 of 2
Debugging step by step (continued)
Change only one thing, then test. Change three things at once and you will not know which one fixed it.
The explanation · step 4 of 4
Common Scratch bugs
| Bug | What you see | Fix |
|---|---|---|
| Variable never reset | The score starts at the last game's number | Put set [score v] to (0) under when green flag clicked |
| Wrong sign | Lives go up instead of down | Use change [lives v] by (-1) |
| Missing loop | The sprite moves once, then stops | Put the blocks inside forever or repeat |
| Wrong number | Repeat 3 with turn 90 draws only three sides of a square | Use repeat (4) |
| Blocks in the wrong order | The sprite says 'Done!' before it moves | Drag the say block below the move blocks |
| Script on the wrong sprite | The wrong sprite moves | Drag the script onto the right sprite |
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Worked example
This script should count lives down from 3 and then say 'Game over'. It never says it. Why? Script: set lives to 3. Repeat until lives = 0: wait 1 second, change lives by 1. Say Game over.
- Predict: lives should go 3, 2, 1, 0, then the sprite says 'Game over'.
- Run: lives go 4, 5, 6, 7 … and never stop.
- Compare: lives go up, not down, so they never reach 0.
- Find: the block
change [lives v] by (1)adds 1. - Fix: change it to
change [lives v] by (-1)and run it again. - Explain: 'The loop never ended because lives went up, so they never reached 0.'
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Quick quiz · 1 of 3
How many times does FOR i ← 2 TO 8 repeat?
- A 8
- B 6
- C 7
C. 7
Both ends count: 8 − 2 + 1 = 7 (2, 3, 4, 5, 6, 7, 8).
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Quick quiz · 2 of 3
Which loop always runs at least once?
- A FOR i ← 1 TO 0
- B REPEAT … UNTIL
- C WHILE … ENDWHILE
B. REPEAT … UNTIL
REPEAT … UNTIL checks its condition at the end, after the first run.
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Quick quiz · 3 of 3
x ← 4, then x ← x × 2, then x ← x + 1. What is x?
- A 8
- B 12
- C 9
C. 9
4 × 2 = 8, then 8 + 1 = 9. Each line replaces the old value.
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Exit ticket
Answer on paper before you go. Then check.
Which shape is used for OUTPUT total?
A ParallelogramB DiamondC Rectangle
A. Parallelogram Input and output are always parallelograms.
Breaking a problem into smaller parts is…
A IterationB DecompositionC Abstraction
B. Decomposition De-compose = take apart.
Year 7 · Scratch I: Programming essentials · Lesson 5 of 5
Homework and the challenge
Homework
Study page 11 to step 5; the 'Trace a loop' practice.
End-of-unit challenge
Trace and fix three buggy scripts, then extend one with a new feature.