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.

  • Lesson 3 of 4
  • PRO
  • Ages 10+
  • 3 hands-on levels
See what PRO unlocksA one-time $49.99 purchase. Topics 1–3 are free.

The dragon explains

Syntax, runtime, and logic errors

  1. The dragon: 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.

  2. The dragon: SYNTAX errors: the grammar itself is broken. Python won't run ANY of the code — not even the lines before the mistake.

    example.pyPython 3
    if True    print("hi")
    OutputSyntaxError: expected ':'
  3. The dragon: 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.

    example.pyPython 3
    print(gold)
    OutputNameError: name 'gold' is not defined
  4. The dragon: LOGIC errors are the strange one: the code runs PERFECTLY. No traceback. No red text. It just quietly does the WRONG thing.

    example.pyPython 3
    def add_gold(current, amount):    return current - amountgold = 100gold = add_gold(gold, 50)print(gold)
    Output50
  5. The dragon: That 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.

  6. The dragon: 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.

Quick check

Check your understanding

Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.

  1. Question 1 of 2

    if gold > 100 (missing colon) — what kind of error is this, and when does it happen?

    question.pyPython 3
    if gold > 100    print("Rich!")
    • A SyntaxError — Python won't run ANY of the code until this is fixedCorrect
    • A runtime error — it happens partway through running, like a NameError
    • A logic error — the code will run but give the wrong answer

    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.

  2. Question 2 of 2

    if gold < 100: print("Can afford it!") — with gold = 150, this prints nothing. Why is there no error message?

    question.pyPython 3
    gold = 150if gold < 100:    print("Can afford it!")
    • It's a logic error — the code is completely valid, the CONDITION is just wrongCorrect
    • There should be an error, and this is a bug in Python itself

    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.

In the game

What you'll practice

Three levels in the game: one guided first try with the shape of the answer already there, then two to solve on your own.

  1. 1

    GuidedYour first try

    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.

  2. +2

    PracticeTwo more, on your own

This lesson is part of PRO.

PRO is a one-time $49.99 purchase, no subscription, and unlocks this whole topic along with everything else. Topics 1–3 are free, start to finish.

Unlock this lesson with PRO

Stuck three times? The game offers the answer — unasked.