When a program stops: errors
Read Python's error messages, tell syntax errors from runtime errors, and fix the line they point 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
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.
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.
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.
- 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.
printandPrintare different names. Fix the first error, run again, and repeat.