runtime
05 / 250
lesson 05 Python Setup & First Programs · beginner

When a program stops: errors

Read Python's error messages, tell syntax errors from runtime errors, and fix the line they point to.

You'll be able to
  • Tell a syntax error (nothing runs) from a runtime error (stops partway)
  • Read an error's type, message and line
  • Fix a NameError, including a capital letter in the wrong place
The idea

Some mistakes Python finds before running anything: syntax errors, like the indentation errors in the last lesson. Others only show up when Python reaches the line: runtime errors. The program runs normally up to that line, then stops.

Run each example to see what it prints. Running examples doesn't count toward progress.

example-1.py · Stops at line 2
print("Checking order O101217")
prnt("Status: delivered")
print("Done")

Read the error from the bottom up. The last line gives the type (NameError) and the message (name 'prnt' is not defined). Above it, the traceback names the line. Start your fix there.

Python names are case-sensitive. print and Print are different names. Print(...) is a NameError too, the same kind of mistake as a typo, because no name Print exists.

example-2.py · Text without quotes
print("Paid in full")
print(paid)

A syntax error stops everything before it starts; a runtime error stops partway. Either way, fix the first error, run again, and read the next one.

Review
  • Syntax errors stop the program before it starts; runtime errors stop it partway.
  • Read the last line first: error type and message, then the line number.
  • print and Print are different names. Fix the first error, run again, and repeat.
Practise this

Loading your progress…

To master this lesson, solve both challenges without hints or the answer, and pass the concept check.

When a program stops: errors — Python Setup & First Programs · Runtime