Class 7 · CBSE AI · Strand B — Python for AI
Error messages are friends — reading Python tracebacks
An error message tells you exactly what went wrong and where. How to read a Python traceback. For Class 7.
Class 7 · CBSE AI · Strand B — Python for AI
An error message tells you exactly what went wrong and where. How to read a Python traceback. For Class 7.
Cooking with a recipe
If your dish tastes wrong, a good cook does not throw away the entire recipe — they taste at each stage to find where it went wrong. Debugging is the same: the traceback is the dish telling you 'it went wrong in step 3', not 'the whole recipe is rubbish'.
Train delay announcement
A railway announcement that says 'Train 12345 is delayed by 45 minutes due to a signal failure at Pune Junction' is infinitely more useful than 'the train is late'. A Python traceback is equally specific — it tells you exactly which train (function), which station (line), and what went wrong (error type). Learn to read it like an announcement.
Every Dhee Learning session for this concept follows three stages. We share the questions Dhee actually asks, so you can hear what a session sounds like.
Stage 1 — Surface
You get a red error message in Colab. Most beginners panic and delete the code. What should a confident programmer do first — before changing a single character?
Rote answer
"Read the error message"
Understood
"Read the last line of the traceback first to identify the error type and message, then trace upward to find which line of my code triggered it — only then start thinking about what caused it"
Stage 2 — Reasoning
Here is an error: 'KeyError: student_name'. You get this when running a line that says print(student['student_name']). What are three possible causes, and how would you test each one?
Follow-up Dhee may use: What is the difference between a KeyError, a TypeError, and an IndexError? Give me a one-sentence example that would cause each one.
Stage 3 — Application
Here is a broken snippet of code with three errors. Without running it first, read it and find as many errors as you can. Then run it, read the traceback, and fix one error at a time. What changed between what you spotted by reading and what the traceback revealed?
Misconception Dhee watches for: Changing multiple things at once to fix an error — this makes it impossible to know which change fixed the problem and may introduce new bugs
Dhee turns this concept into a 15-minute spoken session — asking, listening, and probing — so your child builds the idea themselves.
An error message tells you exactly what went wrong and where. How to read a Python traceback. For Class 7.
An error means you are bad at coding — in reality, even experienced engineers write bugs constantly; the skill is in reading and fixing them efficiently
Dhee opens with a question — for example: "You get a red error message in Colab. Most beginners panic and delete the code. What should a confident programmer do first — before changing a single character?" — listens to your child's answer, then probes the reasoning behind it. The session ends when the child can apply the idea to a brand-new situation, not just recall it.