Playing Through Errors
Errors aren’t interruptions — they’re landmarks. Every blank window, crash, freeze, or traceback is a clue that tells you exactly where the edge of the map is. This chapter teaches you how to read those clues and keep playing.
When something breaks, it means you changed something meaningful. You touched a boundary. You poked the system. That’s progress — not failure.
Python’s error messages look intimidating at first, but they’re actually incredibly helpful once you know how to read them.
When Python hits an error, it prints a “traceback.” This is a breadcrumb trail showing exactly where things went wrong.
File “drifting_stars.py”, line 42, in <module>
star[0] += star[2]
TypeError: unsupported operand type(s) for +=: ‘str’ and ‘float’
This tells you three things:
- Which file broke
- Which line broke
- Why it broke
In this case, a value that should be a number became a string — probably because of a tweak. Easy fix.
1. NameError — Python can’t find a variable.
Usually a typo or a variable used before it exists.
2. TypeError — You mixed types that don’t go together.
Happens when a number becomes a string or vice‑versa.
3. IndexError — You tried to access something outside a list.
Happens when tweaking star or ball arrays.
4. Pygame error — Usually means the window closed early.
Happens when the loop keeps running after the window closes.
1. Read the last line first.
That’s the actual error.
2. Go to the line number.
Python tells you exactly where to look.
3. Undo your last tweak.
If the error disappears, you found the cause.
4. Change one thing at a time.
This is the heart of the Play‑First Loop.
5. Ask AI for help.
Copy the traceback and paste it into your AI assistant. It will explain the error in plain English.
Open any of your previous projects and intentionally cause an error. Delete a bracket. Change a type. Remove a variable. Then fix it.
This is how you build intuition — not by avoiding errors, but by dancing with them.