Camp 1 · Schritt 4 von 23
Comments and error messages
Leave notes in your code with comments — and learn to read error messages like a friendly guide, not a scolding.
Two skills separate people who stick with programming from people who quit in week one: writing notes to your future self, and staying calm when the computer complains. Let's build both.
Comments: notes Python ignores
Anything after a # on a line is a comment — Python skips it entirely.
Comments exist for humans:
Three everyday uses:
- Explaining why —
# freeze one day per week so streaks survive rest days - Temporarily disabling code — put
#in front of a line to "switch it off" - Leaving TODO markers —
# TODO: handle negative numbers
Your first error message
Run this — it's broken on purpose:
You'll get a SyntaxError — Python's way of saying "I couldn't even
understand this as Python." Here it means a ) is missing. Add it and run
again.
Reading a traceback
Now a different kind of error:
This is a NameError: the code is valid Python, but mesage doesn't
exist (we never created it — and we probably meant something spelled
differently). Error messages follow a pattern:
| Part | What it tells you |
|---|---|
Error type (NameError) | The category of problem |
| The message | What exactly went wrong |
| The line number | Where to look |
That's not the computer scolding you. It's the computer filing a very precise bug report, for free, in milliseconds. Experienced programmers see error messages all day long — the skill isn't avoiding them, it's reading them.
Python shows: NameError: name 'contn' is not defined. What's the most likely cause?
What does the line: # print('hi') do when the program runs?
Camp 1 complete! 🏕️
You know what programming is, you've written real programs, and you can read error messages. That's the whole first camp. Next up: variables — teaching Python to remember things.