TwiddleLab / Code / How a Programmer Thinks
Bugs Are Clues
What you will learn
- An error message says where (the line), what kind (the error type) and the details.
- NameError: Python doesn't know that name. Often a typo, or a box used before it was filled.
- SyntaxError: Python can't read the line, like a missing colon or bracket.
- TypeError: the wrong kind of value, like "5" + 3.
How the lesson goes
Red text. Most people panic. Programmers read.
This code stopped with an error. Tap the line you think is broken.
The message has three parts. Each one points somewhere.
Drag each colored part to the place it points at.
Now fix it.
Tap the word the message named, pick the right one, then Run.
Three kinds of error you will meet every day.
An error message is Python telling you where it stopped and why: the line, the kind of error, and the details.
NameError: a name Python doesn't know, like scroe. Usually a typo, or a box used before anything was put in it.
SyntaxError: Python can't even read the line. A missing colon after if, or a bracket that never closes.
TypeError: the wrong kind of value for the job. "5" + 3 mixes text and a number, and Python refuses to guess.
Break it on purpose: collect all three kinds.
Tap an underlined part, pick a change. One change at a time. Fewest edits wins.
Which error would each line cause?
Drag each broken line into its jar. Nothing else is defined.
Print the total price: 4 each, 3 of them.
Put the lines in order. A box has to be filled before it's used.
An AI helper wrote this. It says it works.
Run it. If it breaks, follow the message and fix it.
No arrows this time. Which line needs fixing?
Read the message and tap the line.
The same red message, before and after this lesson.
Slide from Before to After.
Previous lesson: Decisions: if · Next lesson: Loops: Do It Again · Part of the course: How a Programmer Thinks
Lessons are interactive and need JavaScript. Turn it on to play them.