KS3 · Computer Science

Understanding Python errors

Your program runs. No red text, no complaints. One tiny problem: the answer is wrong. Which is sneakier, a program that shouts at you or one that stays silent?

Computing · Python

Name that error

Be the detective. Three suspects, eight faulty programs. Pick a program, decide which kind of error it has, and you'll see straight away why it belongs there.

Still to sort

Syntax error (0)

Broke the rules of the language

Where the line is: If the program will not run until the code is fixed, the rules of the language were broken. That's syntax.

Logic error (0)

Runs without failing, but the result is wrong

Where the line is: The program runs to the end. If the answer isn't what was needed, it isn't syntax and it isn't runtime. It's logic.

Runtime error (0)

Code is fine, but the input or environment makes it fail

Where the line is: The code follows the rules and is logically correct. What breaks it is what the program is given while it runs.

8 of 8 still to sort.

Watch out: A program that runs without a single complaint can still be wrong.

Computing · Debugging

Find the line that breaks the rules

This program should welcome anyone aged 13 or over. Press run and it won't start. Which line is the culprit?

A student's program — which line goes wrong?

Predict, then check

Read it the way Python would: one line at a time.

Here's a program with three mistakes. 1: mark = 55 | 2: print("Checking your mark" | 3: if mark >= 70 | 4: (indented) print("Merit") | 5: if mark >= 50: | 6: (indented) print("Pass") | 7: else: | 8: (indented) print("Try again"). The mistakes: line 2 is missing its closing bracket, line 3 is missing its colon, and line 5 should have been an elif. Which of these stop the program from running?

Computer Science · Algorithms

Trace table — dry run the code

This program should accept ages 13 to 19 only. Step through it with an age of 30 and watch what it does.

1age = 30
2if age >= 13 or age <= 19:
3 print("Accepted")
4else:
5 print("Rejected")
age
age >= 13
age <= 19
branch taken
Output
Press Start to run the first line.
·

Ready when you are — step through one line at a time.

Computing · Testing

The silent program

You run your program. It finishes. There is no error message at all, and you're about to say it's done.

Which is closest to what you think right now?
How sure are you?

Computing · Debugging a project

Put the debugging steps in order

The order you would do the five steps of debugging a project

1 · Do this first5 · Do this last
  1. Fix the bug

  2. Test the bug fix

    Does the code now do what it should?

  3. Identify the bug

  4. Review the task

    What should the project do?

  5. Test the project

    See what goes wrong.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

What you need to know

  • A bug is a mistake in code that stops it working as expected. Debugging is finding and correcting it.
  • Python programs can go wrong in three ways: syntax errors, logic errors and runtime errors.
  • A syntax error means you broke the rules of the language, so the program will not run until it's fixed.
  • Have a goPython flatly refuses to start your program until you change one line. Which of the three kinds of error is that, and what have you broken?

    A syntax error. The rules of the language have been broken.

    A program with a syntax error will not run until the error is fixed.

  • Common syntax-error causes: spelling or typing slips, missing brackets, missing colons, and missing or unexpected indentation.
  • Most IDEs (integrated development environments) highlight syntax errors; in many, a missing speech mark shows in a different colour.
  • Have a goYour editor suddenly turns half a line a different colour, as if it's judging you. What has it probably spotted?

    A missing speech mark, which is a syntax error.

    In many IDEs a missing speech mark is flagged by a different colour, which is a sign that the rules of the language have been broken.

  • With a logic error, the program can run without failing, but it doesn't return the result you expected.
  • Have a goMarcus's program should add 2 and 3 but prints 6. There's no error message, so Marcus says: 'No complaints, so it's perfect!' What's wrong with that?

    It's a logic error. The program ran without failing but didn't give the expected result.

    A program with a logic error can run without failing, so a lack of error messages doesn't show that it's right.

  • Common logic-error causes: misunderstanding the task, the wrong logical operator in a selection, or a loop running too often or too rarely.
  • Logic errors are typically harder to find than syntax errors, because the IDE can't pick them up or give clear messages.
  • A runtime error happens while the program runs: the code is valid and logical, but the input or environment causes the error.
  • To debug during development: find the error, read the error message, trace to where it occurs, fix it, then run it again.

The big picture

Python programs can go wrong in three ways. A syntax error breaks the rules of the language, so the program will not run. A logic error runs without failing but gives the wrong result, and the IDE can't pick it up. A runtime error happens when the input or environment makes valid, logical code fail while it runs. Debugging is finding and correcting these errors.

Key points

1Syntax error: the rules of the language were broken, so the program won't run until it's fixed, and an IDE will usually flag it.
2Logic error: the program runs, but the result isn't what was needed. The IDE can't spot it, so you test against what the program should do.
3Runtime error: valid, logical code fails while running because of the input or environment, such as a string entered where an integer is required.
4Debugging means finding and correcting errors, and every programmer has to do it.
5Two debugging routines: during development (find, read the message, trace, fix and run again), and for a whole project (review the task, test, identify, fix, test the fix).

Worked example

Problem

A program should print Hello three times, but it prints Hello four times and shows no error message. The loop line is: for i in range(4): and it contains print("Hello"). Debug it using the five steps for debugging a project.

⚠ Watch out

Believing that no error message means no bugs. A logic error runs without failing, it just doesn't give the expected result, and the IDE can't pick it up. Silence isn't proof, so test the program against what it should do.

🧠

Memory hook

Syntax won't start. Logic runs but gets it wrong. Runtime falls over on the input.

✓

Check yourself

Explain one kind of error to a friend: what happens when you run the program, and what could cause it? Then say which kind is hardest to find, and why.

Flashcards

(12)
What is a bug, and what is debugging?
A bug is an error or mistake in code that stops it working properly or as expected. Debugging is the process of finding and correcting errors in program code.
Name the three kinds of error you meet when testing Python programs.
Syntax errors, logic errors and runtime errors.
What is a syntax error?
An error that happens when you haven't followed the rules of the language. The translator flags it, and the program will not run.
Give four common causes of syntax errors.
Spelling or typing errors, missing brackets, missing colons, and missing or unexpected indentation.
What does an IDE usually do with syntax errors?
Most IDEs highlight syntax errors when you try to run your code. In many IDEs, a missing speech mark shows up in a different colour.
What is a logic error?
An error that makes a program work incorrectly or unexpectedly. The program can run without failing, but it doesn't return the expected result.
Why are logic errors harder to find than syntax errors?
The IDE can't pick them up or produce clear error messages, so you have to test the program against what it should do.
Name three common causes of logic errors.
Not correctly understanding what the program needed to do, using the incorrect logical operator in a selection statement, and loops that run more or fewer times than intended.
What is a runtime error?
An error that occurs when the program is run. The code is valid and logically correct, but the environment or the input causes the error.
Give an example of what can cause a runtime error.
Erroneous data, such as a string entered where an integer is required.
What are the steps for debugging a program during development?
Find the error, read the error message, trace through the code to detect where it occurs, then fix it and run the code to check that the update works.
When debugging a project, why do you review the task before anything else?
So you know what the project should do. Then, when you test it, you can see what goes wrong.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More KS3 Computer Science topics

See the full KS3 Computer Science curriculum →

How this lesson was checked. This KS3 Computer Sciencelesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 7 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.

Helpful guides for parents and students