Rocket presses F5 on his new fuel report and the shell fills with red text. He pushes back his chair. "It is broken," he says. "Everything is broken."
Raven rolls her chair closer and reads the red lines from the bottom up. "What do you notice?" she asks. "It is not everything. The very last line names one problem, and another line gives a line number."
Nova hovers beside the screen and highlights one word. "Let's debug together," she says. "Python is not angry. It is telling you exactly where it got stuck."
Rocket takes a deep breath, pulls his chair back in, and reads the message slowly from the bottom.
A syntax error means Python cannot even read the program, like a sentence with a missing quote mark. IDLE shows a box called SyntaxError and colors the spot in red. Nothing runs at all.
A runtime error happens while the program runs. The lines before the problem run fine. Then Python stops and prints a traceback in the shell.
print("Fuel check) This one line has a syntax error. The string starts with a quote mark but never ends with one. Python says: unterminated string literal. Unterminated means it never ends.
print("Fuel report")
print("Tank A:", 40)
prnt("Tank B:", 35)
print("Done") When you run it, the shell shows this. Your copy will show the full path to your file, and older versions of Python leave out the Did you mean part.
Fuel report
Tank A: 40
Traceback (most recent call last):
File "fuel_report.py", line 3, in <module>
prnt("Tank B:", 35)
^^^^
NameError: name 'prnt' is not defined. Did you mean: 'print'? Python names are case sensitive. That means print and Print are different names to Python, so a capital letter can cause a NameError.
A missing round bracket is a syntax error. Python reports that a bracket was never closed, and nothing in the file runs.
print("Status board")
Print("All clear")
print("End of report") | Statement | True or false? |
|---|---|
| print and Print mean the same thing to Python. | ? |
| With a syntax error, no lines of the file run. | ? |
| With a runtime error, lines above the problem still run. | ? |
| The first line of a traceback names the kind of error. | ? |
Every programmer sees error messages every day, and reading them calmly is a real skill. You finished your first week as Mission Commander. Tomorrow is a Crew Quest.