Concept Explanation
Debugging is the moment where programming stops being theory and starts feeling real. You write something that looks correct, run it with confidence, and Python immediately shows you that one detail is wrong. That is not failure. That is normal development. In this lesson, you will practice reading an error instead of reacting emotionally to it. The script below has a small but realistic mistake: the data exists, but the wrong variable name is passed into the function. After fixing that, you will deliberately trigger a second problem so you can see how a different kind of error feels. The goal is not just to make the program work. The goal is to build a calm habit: run the file, read the traceback, fix one thing, and test again. By the end of this lesson, you should be able to: • use the traceback to find the real line that failed, • explain why a `NameError` happens in plain language, • fix one bug at a time instead of changing random parts of the script.
Where to Put the Code
- Define color and position variables at the top.
- Create shape drawing or placement logic in the middle.
- Render output (print, canvas, SVG, or styled block) at the end.
Command Reference
- Read the last line of the traceback first; it usually tells you the real error type and the exact line.
- If you see `NameError`, look for a variable that was misspelled, never created, or renamed in only one place.
- Fix one problem, run the file again, and only then move to the next problem.
- Do not guess blindly; let the error message guide your next edit.
Step-by-step Guide
- Run the script once without changing anything and read the traceback slowly from bottom to top.
- Find the line that caused the `NameError` and replace `username` with `learner_name`.
- Run the file again and confirm that the greeting now prints correctly.
- After that works, set `learner_name = None` on purpose and run the file again to see a different error.
- Restore the valid string and write one short note about what changed between the two errors.
Practice Exercises
- Create a second `NameError` on purpose by changing one variable name in only one place, then fix it.
- Explain in your own words why `build_greeting(username)` failed before the function could even run correctly.
- Add one simple guard that stops the function from accepting an empty string after you finish the debugging steps.
Coding Challenges
- Store the greeting in a variable first, then print it only after you are sure the function succeeded.
- Write a tiny checklist you can follow in future debugging sessions: error type, file, line, variable, rerun.
Mini Practice Tasks
- Copy the exact `NameError` message into your notes.
- Say out loud which variable exists and which one does not before you fix the code.
- Keep one sentence for yourself: `A traceback is information, not a disaster.`
Common Mistake
Mixing x and y axes or using wrong coordinate origin causes shapes to appear in unexpected places.
Real-life Mini Challenge
Draw one square, one triangle, and one circle, then move X marker 2 steps right and 1 step down.