Computer Science Essentials, Unit 4, Lesson 2 of 5

Fixing programs

GCSE Computer Science, Onscreen programming, 35 minutes

Sign in

Syntax, runtime and logic errors, reading Python's error messages, and the bugs that come up again and again: limits, loops that run the wrong number of times, input never converted, totals reset and returns in the wrong place.

What you will learn

  • Tell a syntax, a runtime and a logic error apart
  • Use an error message to find the line at fault
  • Fix comparisons at the limits and loops that run the wrong number of times
  • Fix running totals, counts and returns that are in the wrong place

Three kinds of error

  • A syntax error breaks the rules of the language, such as a missing colon or bracket. The program will not run at all.
  • A runtime error happens while the program runs: it starts, then stops part way with an error message, such as dividing by zero, using an index that does not exist, or joining text to a number with + ("Total: " + 5 stops with a TypeError; "Total: " + str(5) works).
  • A logic error lets the program run to the end, but the result is wrong, such as a total that is one item short.

Python names the line where it found a syntax or runtime error, and the kind of error: SyntaxError, IndexError, TypeError, ValueError or ZeroDivisionError. A logic error gives no message, so the tests are how you find it.

The rest of this lesson and its 9 practice questions are locked.

In this lesson

  1. Three kinds of error
  2. A method for fixing a program
  3. The bugs that come up most
  4. Try it: Name the error

9 practice questions, marked as you go; about 35 minutes in all.

Key terms

Syntax error, Runtime error, Logic error, Limits, Loops one short, Input never converted, Indentation

In this unit: Onscreen programming

Partly written Python programs to complete, amend, fix and extend, checked by running them against tests: subroutines, 2D lists, records from files, validation, strings and longer tasks in parts.

All of Onscreen programming