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.
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.
Ready when you are — step through one line at a time.
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
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?
Name the three kinds of error you meet when testing Python programs.
What is a syntax error?
Give four common causes of syntax errors.
What does an IDE usually do with syntax errors?
What is a logic error?
Why are logic errors harder to find than syntax errors?
Name three common causes of logic errors.
What is a runtime error?
Give an example of what can cause a runtime error.
What are the steps for debugging a program during development?
When debugging a project, why do you review the task before anything else?
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 postedMore KS3 Computer Science topics
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.