BeginnerCoder

Lesson 10 — Explaining an error to the assistant

A good bug report gets a good fix

"My code doesn't work, fix it" forces the assistant to guess. A good bug report has:

  • the code;
  • what you expected;
  • the error — the last line of the traceback;
  • where it happened — the line number and that line of code.

A traceback is Python's error report. Read it from the bottom up: the last line is the error type and message; the File "...", line N just above it is where it happened, and the line under that is the code itself.

  File "main.py", line 4, in average
    total += s
TypeError: unsupported operand type(s) for +=: 'int' and 'str'

Handy string tools: text.strip().splitlines() gives a list of lines; lines[-1] is the last one; line.split("line ")[1] gives what comes after "line ".

Why it matters: the error is the most precise clue you have. Passing it on exactly is half of the fix.

Want it another way?
Task

Finish bug_report(): fill error with the last traceback line, and number + code_line from the last "File ..." line and the line after it.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Coding with AI: ChatGPT & Claude

Ready for more? Optional paid resources that pick up where this lesson leaves off.

Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.