Study Guide Instructor view
Finding and Fixing Errors
Teaching notes for Lesson 5.14, with controls for presenting it.
Keep this page on your own screen. Share only the lesson window. The lesson window holds no teaching notes, so sharing it cannot show them.
Presenting
- Open the lesson in its own window and share that window, not this one.
- Use Next and Previous here, or the lesson’s own, to move through the lesson. Next reveals one thing at a time: the next idea, or the answer to the question on screen, then the next step. Previous takes the last reveal back. The line below says what is on screen and what Next will show.
- Reveal hints and answers when the class is ready, and reset a demonstration before using it again.
The controls need JavaScript and a browser that supports BroadcastChannel. Without them, open the lesson in presentation mode and use its own controls.
The two windows talk to each other only inside this browser, on this device. Nothing is sent to a server, and no account is needed. A second device (a phone or another tablet) cannot follow the lesson window yet.
Now on the lesson window
- On screen
- Next teaching point
Guidance for this point
Lesson plan
- Level
- Intermediate
- Time
- About 90 minutes; the steps below add up to 94
Pupils start from two different messages on one program, discover that a computer can report broken rules but not wrong intentions, and then learn to find logic errors by working out the expected result and tracing. Four standard faults are met in turn, and the lesson ends with pupils rewriting a badly written program so that others can maintain it.
Objectives
- Tell a syntax error from a logic error, and say how each shows itself
- Use a trace table and the expected result to find the line where an algorithm goes wrong
- Recognise off-by-one, wrong-operator, wrong-starting-value and wrong-loop-condition errors, and suggest a correction for each
- Explain what makes a program maintainable: meaningful identifiers, comments, indentation, constants and subroutines
- Improve a badly written program so that it is easier to read and change
Before the lesson
- Mini whiteboards for predictions before each trace.
- Printed copies of the four faulty programs for pairs to annotate, if the class prefers paper.
- A badly written program on the board for the maintainability step, with room beside it to rewrite names.
Steps
Introduction Opening
On the lesson window now
On screen: the lesson’s title, module and number; Next adds its objectives and key terms, as the lesson page lists them; Next again begins the first step.
Objectives on screen
- Tell a syntax error from a logic error, and say how each shows itself
- Use a trace table and the expected result to find the line where an algorithm goes wrong
- Recognise off-by-one, wrong-operator, wrong-starting-value and wrong-loop-condition errors, and suggest a correction for each
- Explain what makes a program maintainable: meaningful identifiers, comments, indentation, constants and subroutines
- Improve a badly written program so that it is easier to read and change
Purpose: Pupils start from two different messages on one program, discover that a computer can report broken rules but not wrong intentions, and then learn to find logic errors by working out the expected result and tracing. Four standard faults are met in turn, and the lesson ends with pupils rewriting a badly written program so that others can maintain it.
1. Two problems, two kinds of message Think 7 min
On the lesson window now
Purpose: Pupils notice that the computer can report one kind of fault and not the other, before either has a name.
Ask
- Why did the computer report INPT but not the total of 16?
- How could Zara find the second fault?
Responses to expect
- INPT breaks the language; 16 follows the rules but is not what she meant
- Work through it with the same scores
Misconceptions to challenge
- A learner may believe: “If a program runs, it is correct.” Respond: It does what its lines say, which may not be what was meant.
Discussion pause: Thirty seconds, then pairs agree an answer.
In the lesson window
- Think it through: The computer told Zara about the first problem but said nothing about the second. Why do you think that was? How could Zara find the second problem herself?
2. Breaking the rules, and following them wrongly Discover 10 min
On the lesson window now
Purpose: Naming syntax and logic errors by sorting four faults, then classifying two more.
Ask
- Which two groups are the four faults in?
- Which kind of error can the computer find by itself?
Responses to expect
- Breaking the rules, and following the rules wrongly
- A syntax error
Misconceptions to challenge
- A learner may believe: “A wrong answer means a syntax error.” Respond: A syntax error stops the program from running; a wrong answer from a running program is a logic error.
Checking understanding: The two classification questions each have one clear case.
Depending on the answers
- If pupils call the rectangle program a syntax error: ask whether it ran, and what the computer would say about 11 against 24
In the lesson window
- Think it through: Sort these four faults into two groups, with a reason for the grouping: (1) the keyword ENDIF is spelt ENDFI; (2) a program for the area of a rectangle adds the length and the width instead of multiplying; (3) a FOR loop has no NEXT; (4) a loop that should run 10 times runs 9.
- Check your understanding: A program has the line FOR Round ← 1 TO 4 but no matching NEXT Round. What kind of error is this?
- Check your understanding: A program for the area of a rectangle contains Area ← Length + Width. It runs, and outputs 11 for a 3 by 8 rectangle. What kind of error is this?
3. Following a program to where it goes wrong Predict 12 min
On the lesson window now
Purpose: A method for finding a logic error, with the off-by-one error as its first case.
Ask
- How many scores does the loop read?
- Where in the trace does the program stop matching the plan?
Responses to expect
- Four
- After the fourth row: there is no fifth
Misconceptions to challenge
- A learner may believe: “The fault must be in the adding line.” Respond: Each row adds correctly. The fault is the number of rows.
On the board or with the pen
- Write the five steps of the method on the board and refer to them in each later step.
Checking understanding: The fix-zara question: count the passes of each loop.
Support
- Provide the trace table with the Round column filled in and ask for the totals only.
In the lesson window
- Think it through: Without running it, work out how many scores the loop reads. Which score does Zara’s program never use, and what does it output for the scores 3, 5, 2, 6 and 4?
- Check your understanding: Which change corrects Zara’s program?
4. One symbol out Explain 10 min
On the lesson window now
Purpose: Pupils predict which age differs, then trace to see a boundary fault.
Ask
- What price should 12 pay?
- Which age does the program get wrong?
Responses to expect
- £8, because it is not under 12
- 12
Misconceptions to challenge
- A learner may believe: “<= and < mean the same.” Respond: Test the age on the limit: 12 <= 12 is true, 12 < 12 is false.
Checking understanding: The fix-cinema question diagnoses four different wrong repairs.
Depending on the answers
- If pupils choose >=: test the age 5 against it together
- If pupils ask how this was found: connect to boundary test data from Lesson 13
In the lesson window
- Think it through: Work out the expected price for the ages 11, 12 and 13 from the cinema’s rule, and then the price the program gives. For which age do they differ?
- Apply it: Which correction makes the program match the rule “children under 12 pay £4”?
5. Where a program starts from Predict 10 min
On the lesson window now
Purpose: A starting value that the data cannot beat, discovered by prediction and trace.
Ask
- What is the highest of -3, -8 and -1?
- What does the program output, and why?
Responses to expect
- -1
- 0, because nothing beats the starting 0
Misconceptions to challenge
- A learner may believe: “Starting from 0 is always safe.” Respond: Not for negative data. Start from the first value in the data.
- A learner may believe: “A missing starting line is fine because the variable starts at 0.” Respond: A variable that was never set has no sensible value; write ? in the trace table.
Checking understanding: The fix-highest question distinguishes starting from the data from starting from a guess.
In the lesson window
- Think it through: What is the highest of the three temperatures? Predict what the program outputs, and say which line you think causes it.
- Check your understanding: Which correction makes the program give the right answer for any temperatures, including negative ones?
6. A loop that never starts Predict 9 min
On the lesson window now
Purpose: A loop condition the wrong way round, found by predicting and tracing the first test.
Ask
- What is Number after the first INPUT?
- Is Number = 0 true or false then?
Responses to expect
- 4
- False, so the loop never runs
Misconceptions to challenge
- A learner may believe: “A WHILE loop runs until its condition is true.” Respond: It runs while its condition is true. REPEAT … UNTIL is the one that runs until.
On the board or with the pen
- Write WHILE keeps going while … and REPEAT keeps going until … side by side.
Checking understanding: The fix-while question; each wrong option is a different misreading of the condition.
In the lesson window
- Think it through: Predict what the program outputs for 4, 6 and 0. Then say which one line is wrong, and what it should say.
- Apply it: Which correction makes the program output 10 for the numbers 4, 6 and 0?
7. A program nobody can change Think 8 min
On the lesson window now
Purpose: Pupils list what makes a badly written program hard to change before the four habits are named.
Ask
- What do a, b and c stand for?
- What would you have to change if the discount changed?
Responses to expect
- Nobody can tell
- Find the 30 and the 0.1 among the lines
Misconceptions to challenge
- A learner may believe: “If a program works, how it looks does not matter.” Respond: Programs are changed many times by many people; ask who will change this one.
English as an additional language
- Check the words identifier, comment, indentation and constant when they appear.
Discussion pause: Ninety seconds in pairs to list problems.
In the lesson window
- Think it through: Tomorrow the group size for the discount changes from 30 to 40, and the discount from 10% to 15%. List everything that makes this program hard to read and to change.
- Check your understanding: Which comment is most useful above the line Passes ← Passes + 1 in a program that counts pupils who pass?
8. Improve it yourself Apply 12 min
On the lesson window now
Purpose: Pupils rewrite the trip program, then see why constants matter when the rules change.
Ask
- Which numbers are rules that might change?
- How many places change if the limits change?
Responses to expect
- The group size and the discount
- Two
Misconceptions to challenge
- A learner may believe: “Comments should describe every line.” Respond: A comment should say what the code cannot: its purpose or why.
Checking understanding: Collect the paper rewrites and check names, constants, a comment and indentation.
Stretch
- Move the calculation into a function and say what the main program then looks like.
In the lesson window
- Think it through: Rewrite the trip program so that it is easy to maintain. Use meaningful identifiers, constants for the group size and the discount, a comment saying what the program does, indentation and a clear output message.
- Apply it: With the improved version, the group size becomes 40 and the discount 15%. How many places in the program need to change?
9. Find the fault and fix it Apply 10 min
On the lesson window now
Purpose: Independent use of the method: a fault pupils must find and name unaided.
Ask
- What does the program output for 10, 12, 8 and 14?
- Which kind of error, and what is the corrected line?
Responses to expect
- 7.5
- A logic error, off-by-one; FOR Count ← 1 TO 4
Misconceptions to challenge
- A learner may believe: “Sam’s > 50 works because it is close to the right condition.” Respond: The mark of exactly 50 is lost. Always test the limit.
Checking understanding: The paper answers show who can complete the whole method.
Depending on the answers
- If pupils fix only the division: point out that 30 / 3 would give 10, which is still wrong; the data were four marks
In the lesson window
- Think it through: Complete a trace table for the marks 10, 12, 8 and 14, say what the program outputs, name the kind of error and write the corrected line.
- Apply it: Sam’s program counts the marks of 50 or more among 62, 45, 50, 38 and 71. It uses IF Mark > 50 and outputs 2. The correct count is 3. What kind of error is it, and what is the fix?
10. Show what you know Consolidate 6 min
On the lesson window now
Purpose: Explanation of the method, and a last judgement about maintainability.
Ask
- Explain how to find a fault in a program that runs.
- Which single change helps a stranger most?
Responses to expect
- Work out the expected result, trace, find where it differs, name and fix, test again
- Meaningful names and a comment
Checking understanding: Choose two pupils to give the method in their own words.
In the lesson window
- Think it through: Explain to a friend how you would find the fault in a program that runs but gives the wrong answer. Include what you would work out first, what you would do with it, and how you would know you had fixed it.
- Apply it: A program uses the names X, Y and Z for the length, width and area of a room, and has no comments. Which single change makes it most maintainable?
Lesson recap Closing
On the lesson window now
On screen: the lesson’s objectives again; Next adds the closing question, which asks the class to explain each one in their own words without looking back. It says nothing about what anyone has learnt: use the answers to decide what to revisit.
Points to listen for
- Syntax errors break the rules of the language; logic errors give wrong results from a program that runs.
- Find a logic error by working out the expected result and tracing to the first row that differs.
- Common faults: off-by-one, a wrong comparison, a wrong starting value and a wrong loop condition.
- A maintainable program has meaningful names, comments that say why, indentation, constants and subroutines.
Consolidation
- Syntax errors break the rules of the language; logic errors give wrong results from a program that runs.
- Find a logic error by working out the expected result and tracing to the first row that differs.
- Common faults: off-by-one, a wrong comparison, a wrong starting value and a wrong loop condition.
- A maintainable program has meaningful names, comments that say why, indentation, constants and subroutines.