Identifying and Correcting Errors
Introduit| English | Sens |
|---|---|
| bug/bʌɡ/ | bug : bogue |
| debugging/ˈdiːbʌɡɪŋ/ | debugging : débogage |
| syntax error/ˈsɪntæks ˈerə/ | syntax error : erreur de syntaxe |
| logic error/ˈlɒdʒɪk ˈerə/ | logic error : erreur logique |
| runtime error/ˈrʌntaɪm ˈerə/ | runtime error : erreur d'exécution |
| overflow error/ˌəʊvəˈfləʊ ˈerə/ | overflow error : dépassement de capacité |
| edge case/edʒ keɪs/ | edge case : cas limite |
| expected output/ekˈspektɪd ˈaʊtpʊt/ | expected output : sortie attendue |
Every program has bugs
- No matter how careful the team is, programs contain mistakes.
- A mistake in a program is a bug 缺陷.
- Finding and fixing bugs is called debugging 调试.
- Skilled debugging is one of the most valuable abilities a programmer can build.
Which kind of error?
A syntax error stops the program running; a logic error runs but gives the wrong answer; a runtime error crashes it partway; an overflow error exceeds storage.
The work of finding and fixing mistakes in a program is called ______.
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
A mistake is a bug; fixing bugs is debugging.
A missing bracket that stops the program from running is a:
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Breaking the language's rules is a syntax error.
Why are logic errors often the hardest to find?
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Nothing obviously breaks, so you must compare output to what you expected.
The main kinds of error
- A syntax error 语法错误 breaks the language's rules (a missing bracket) — the program refuses to run.
- A logic error 逻辑错误 runs but gives the wrong result, because the instructions do not match the plan.
- A runtime error 运行时错误 crashes the program while it runs — like dividing by zero.
- An overflow error 溢出错误 happens when a value grows too large for its storage space.

A trace table records each variable's value as the program runs, to find bugs
Testing with edge cases (empty input, very large numbers) helps find hidden bugs.
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Bugs often hide at the limits of what a program expects.
To spot a bug in a test, you compare the actual output with the:
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
A difference between actual and expected output points to a bug.
How to find them
- Test with many inputs, including unusual ones — a very large number, empty input, or an edge case 边界情况 at the limit.
- Compare the actual output with the expected output 预期输出; a difference points to a bug.
- Add temporary print statements to see internal values, so you find where it first goes wrong.
- Divide and check: confirm one part is correct, then narrow down the rest.
After fixing a bug, you only need to re-test the line you changed.
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
False. A fix can create a new bug elsewhere, so you should re-test the whole program after changing it.
Fix, then re-test
- Logic errors are the hardest — nothing obviously "breaks," the answer is just wrong.
- Fixing one bug can create another.
- So after every correction, re-test the whole program.
- Careful, repeated testing turns a rough prototype into software people can trust.
"It ran" is not "it's correct." A logic error runs with no crash and no message — the program looks fine but the answer is wrong. The only way to catch it is to compare the output with what you expected, not just check that it ran.
Worked example: finding a logic error
A program should find the average of a list of test scores. For the list [80, 90, 70] it prints 60 instead of 80. The code adds each score to a sum, then divides the sum by (length of list + 1). Classify and fix the bug.
- The program runs and prints a result, so it is not a syntax or runtime error: it is a logic error. Checking by hand: the sum is 240, and $240\div(3+1)=60$, so the divisor is wrong.
- Fix: divide by the length of the list: $240\div3=80$. Then test with more cases, including an edge case such as an empty list, which would cause a runtime error (division by zero) unless the program checks for it first.
A program crashes with "division by zero" when the user enters 0. This is:
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
It happens while the program is running.
Testing only typical inputs is enough to find most bugs.
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Edge cases and unusual inputs reveal many bugs.
A bug is a mistake; fixing bugs is debugging. A syntax error stops the program running, a logic error runs but gives the wrong answer, a runtime error crashes it partway, and an overflow error exceeds storage. Find bugs by testing many inputs (especially edge cases) against the expected output, and always re-test after a fix.