The dragon explains
Reading a traceback bottom-up
The dragon: Every topic so far, a crash just... happened. Now you're going to learn to actually READ one.
The dragon: A traceback looks like a wall of text, but the important part is always the LAST line.
example.pyPython 3gold = 100print(glod)
OutputNameError: name 'glod' is not definedThe dragon: NameError: name 'glod' is not defined. That's Python telling you EXACTLY what's wrong — you tried to use a name that was never created.
The dragon: Above that last line, the traceback also names a LINE NUMBER — exactly where Python was when it gave up.
The dragon: Sometimes that line number points at where the mistake ACTUALLY is. Sometimes it points at where a bad value first gets USED — one line later than where it was really created wrong.
example.pyPython 3golde = 100print(gold)
OutputNameError: name 'gold' is not defined. Did you mean: 'golde'?The dragon: Python complains on the print() line, but the real fix is one line earlier — golde should have been gold from the start. Notice Python even GUESSES the fix for you: "Did you mean: 'golde'?"
The dragon: The habit worth building: read the LAST line first (what went wrong), then the line number (roughly where), then look slightly earlier too if the obvious line looks fine.
Quick check
Check your understanding
Say your answer out loud before reading the marked one. Every wrong option is a mistake real beginners make.
Question 1 of 2
A traceback ends with: NameError: name 'plyer' is not defined. What does this tell you?
question.pyPython 3print(plyer)- A name called plyer was used, but never created anywhere before thisCorrect
- Python's print() function is broken
- The code has a missing colon or bracket somewhere
Why: NameError: name 'plyer' is not defined means exactly what it says — somewhere, code tried to use the name plyer, and Python has never seen it created (no plyer = ... anywhere before that point). Usually a typo for a real variable name.
Question 2 of 2
golde = 100, then print(gold) — where is the traceback's line number likely to point?
question.pyPython 3golde = 100print(gold)
- Line 2 — where gold is USED, even though the real typo is on line 1Correct
- Line 1 — Python always points at where the mistake was actually typed
Why: Line 2 — that's where Python actually tries to use gold and discovers it was never created. The real fix is on line 1 (golde should have been gold), but the traceback can only point at the moment the problem became visible, which is sometimes a line or more after the real mistake. (Python even guesses here — "Did you mean: 'golde'?" — but it can't always do that.)
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
GuidedYour first try
This code crashes. Run it once and look at the very BOTTOM line of what appears — that's where Python names the problem. It says NameError: name 'glod' is not defined. glod is a typo for gold. Fix the typo, then print gold.
- +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 PROStuck three times? The game offers the answer — unasked.