CurriculumReading Python Error Messages, for KidsSyntax, runtime, and logic errors
Syntax Errors vs Runtime Errors vs Logic Errors in Python
Three completely different kinds of wrong — and the hardest one leaves no error message at all.
Syntax, runtime, and logic errors
Every crash you've fixed so far had a traceback pointing at it. There are actually THREE kinds of "wrong," and only two of them look like that.
SYNTAX errors: the grammar itself is broken. Python won't run ANY of the code — not even the lines before the mistake.
if True
print("hi")Output
SyntaxError: expected ':'RUNTIME errors: the grammar is fine, but something goes wrong WHILE running — this is everything you've fixed in segments 1 and 2. NameError, IndexError, TypeError, and friends.
print(gold)Output
NameError: name 'gold' is not definedLOGIC errors are the strange one: the code runs PERFECTLY. No traceback. No red text. It just quietly does the WRONG thing.
def add_gold(current, amount):
return current - amount
gold = 100
gold = add_gold(gold, 50)
print(gold)Output
50That should be 150 (100 + 50), not 50. But Python has no idea anything is wrong — subtracting is completely valid code, it's just not what the story asked for.
This is the hardest kind of bug, because there's no traceback to lean on at all. The only tool is comparing what you EXPECTED against what actually happened.
Check your understanding
if gold > 100 (missing colon) — what kind of error is this, and when does it happen?
if gold > 100
print("Rich!")Why: A SyntaxError. Python checks the code's GRAMMAR before running a single line — a missing colon breaks that grammar, so nothing runs at all, not even the correct lines before it.
if gold < 100: print("Can afford it!") — with gold = 150, this prints nothing. Why is there no error message?
gold = 150
if gold < 100:
print("Can afford it!")Why: A logic error. gold < 100 is valid code that just tests the WRONG thing — with gold = 150, it's False, so the print never runs, and nothing crashes because nothing is actually broken from Python's point of view. Only comparing expected vs. actual reveals it.
What you'll practice
add_gold(current, amount) is supposed to ADD gold, but it's actually SUBTRACTING. Run it — notice there's no error, no red text, nothing crashes. gold starts at 100, add_gold(gold, 50) should make it 150 — but it prints 50 instead. Find the one wrong symbol and fix it.
More from this topic
Syntax, runtime, and logic errors is one lesson inside Reading Python Error Messages, for Kids — see the full lesson order and what the whole topic covers.
View the full topic →