Skip to content

Informatics Practices · Ch 3 — Brief Overview of Python

Debugging

3.9

Debugging

No matter how carefully a program is written, mistakes creep in — and a mistake, or error, can hurt a program in two distinct ways. It may prevent the program from executing at all, or it may let the program run but make it produce wrong output. Either way, the program fails at its job, so recognising what kind of error has occurred is the first step towards fixing it.

Errors in a Python program fall into three categories:

  • Syntax errors — the program breaks the grammar rules of the language, so the interpreter refuses to run it. These must be removed before the program can execute at all.
  • Logical errors — the program runs without complaint, but the instructions themselves are flawed, so the output is wrong.
  • Runtime errors — the program is written correctly as far as the rules of the language go, but something goes wrong while it is executing, and it terminates abnormally. …