Legends ofPythos
Claim your name
Python Basics

When Python complains

Lesson 2 of 13

Watch the lesson1:07 · with Sigrid
Your code will break. Everyone's does, every day, including people who have written Python for twenty years. An error is not a telling-off. It is Python trying to help, and learning to read what it says is one of the most useful things you can pick up early.

Reading the message

When something goes wrong, Python prints a block of text called a traceback. It can look intimidating. The trick is that the last line is the important one — it tells you what went wrong. The lines above it tell you where.
print('Hello)
A string that was never closed
Run that and Python says something like:

SyntaxError: unterminated string literal (detected at line 1)

Read it backwards. SyntaxError means Python could not even understand the line, usually a missing quote or bracket. It even tells you the line number.

The three you will meet first

SyntaxError — Python cannot understand your code. Nearly always a missing quote, a missing bracket, or a missing colon.

NameError — you used a name Python has never seen. Usually a typo, like writing primt instead of print.

TypeError — you asked for something that does not make sense for that kind of value, like adding a number to a piece of text.
primt('Hello')
# NameError: name 'primt' is not defined
A typo in a function name

Your turn

0 of 3 solved

Exercise 1

+20 XP
This code has a SyntaxError — a quote was never closed. Fix it so it prints Hello, world!
print('Hello, world!)

Run your code to check it against the tests.

Exercise 2

+20 XP
This code has a NameError, because the function name is misspelled. Fix it so it prints It works
primt('It works')

Run your code to check it against the tests.

Exercise 3

+20 XP
This one has two problems on two different lines: a missing closing bracket, and a misspelled function name. Fix both so it prints one then two.
print('one'
prnt('two')

Run your code to check it against the tests.