← Demo

Anatomy of a Friendly Error Message

Error / Trace:
Traceback (most recent call last):
  File "main.py", line 2, in <module>
    print("Hello, " + firstname)
NameError: name 'firstname' is not defined
1
Explain & Suggest - Title & Summary
This variable doesn't exist yet
Your code uses the variable "firstname", but it hasn't been created yet. Check line 2. If you meant to print the text firstname, put it in double quotes.
2a
Hint & Direct - Why it happened
Without speech marks Python treats firstname as a variable, and this variable does not exist yet.
2b
Hint & Direct - What to do
  • If it is meant to be text, put speech marks around firstname.
  • If it is meant to be a variable, make it first (for example: firstname = "Jo").
  • Check spelling and capital letters.
3
Solve - Suggested fix
firstname = "Jo"
print("Hello, " + firstname)
Step 1 - Explain & Suggest
Explain the error in plain English and why the code can't run. Use highlighting to draw attention to the relevant line. Suggest which aspect the learner should review - a typo, a missing definition, a syntax issue - posed as a suggestion, not a directive.
Step 2a - Hint & Direct (hint)
Provide more specific detail about why the error happens. Give the learner something concrete to reason about before directing them to act.
Step 2b - Hint & Direct (direct)
Direct the learner - don't suggest. Tell them exactly what to change: "You need to change X at line Y." Be specific and action-oriented.
Step 3 - Solve
Provide a working solution with a brief explanation of what it corrects and why. A last resort - enough to unblock without handing the answer over too early.