A weather app, a spreadsheet's totals, the message that pops up when a parcel ships: each one is a program, and somebody typed every one of them as plain text. This course teaches you to write that text in Python. Before you install anything, it helps to know what happens between typing some words into a file and seeing a computer act on them, because most beginner confusion comes from that gap.
Source code and the interpreter
A program is a list of steps a computer follows to get a job done. A kitchen timer app is a program. Its steps are roughly: count down from the number you chose, then ring.
Inside every computer is a chip that follows the steps, called the processor. It is very fast and very literal. It only understands steps written as numbers, one tiny step at a time, like "add these two numbers". Steps written that way are called machine code, and people stopped writing them by hand long ago.
Instead, people write steps in words and symbols a person can read, using a
programming language. Python is one of those languages. The readable text
you type is called source code. You save it in an ordinary text file,
and a Python file's name ends in .py, the way a photo's name might end in
.jpg.
That leaves a gap: you write readable text, and the chip reads only
numbers. Python fills the gap with a helper program called an
interpreter. Think of a cook reading a recipe card out loud to a
kitchen robot, one line at a time. The card is your source code. The robot
is the chip. The cook is the interpreter: it reads your file and carries
out each step for you. The usual Python interpreter is named CPython, and
in Chapter 1 you'll install it on your computer. Typing python hello.py
means "start the interpreter, and have it follow the steps in the file
hello.py."
One consequence is worth knowing early. The interpreter has to be present
every time the program runs. To share a Python program, you send the .py
file, and the other person needs Python installed too.
A program is a list of instructions a computer carries out, in order, to do a job. The part of the computer that carries out instructions is the processor, and it understands only machine code: tiny operations such as "add these two numbers" or "copy this number over there", each stored as a pattern of numbers. Different families of processor use different machine code.
Nobody writes machine code by hand. People write source code: the text
of a program in a programming language such as Python, typed into an
ordinary text file. Python source files end in .py. Source code is written
for people to read and change, so the processor can't use it as it is.
An interpreter is a program that reads source code and carries it out
for you. Python's standard interpreter is called CPython (the C is for the
language it is itself written in); it's what you'll install in Chapter 1,
and it's what the python command starts. When you run python hello.py,
CPython opens the file and checks that the whole of it follows Python's
grammar. It then translates the file into a compact internal form called
bytecode, and works through that bytecode one step at a time, doing what
each step says. The interpreter is the program actually running on the processor;
your source code is the set of instructions it follows. That's why every
computer that runs a Python program needs Python installed, and why the
.py file is the program you share and keep.
Here is a complete Python program, two lines long. You'll type and run one like it yourself in Chapter 1. For now, just read it.
print("Hello, world!")
print("I am a Python program.")
Hello, world!
I am a Python program.
The box under the code is what the program printed when this page was built, by the real Python 3.14 interpreter. Reading it line by line:
print(...)shows whatever is inside its round brackets, then moves to a new line. You'll learn exactly what kind of thingprintis in Chapter 1.- The double quotes mark where a piece of text starts and stops. The quotes themselves aren't shown; only the letters between them are.
- The lines run top to bottom, so
Hello, world!comes out first.
From hello.py to Hello, world!
Loading interactive…
A program rarely works alone. It reads data (a list of prices, a photo, what a person types) and it produces output (text on the screen, a new file). Source code is the instructions; data is what the instructions work on; output is what comes out. The same program can read different data every time it runs and give different output each time, without its source code changing at all.
Instructions, data, or output?
Sort each item: is it source code (the instructions), data a program reads, or output a program produced?
Loading interactive…
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Correct answer
Also accepted:
Why
Why
.py and lines written in Python are source code. The prices file and the typed name are data: the program reads them but they aren't instructions. Text on the screen and the report file are output: they exist because the program ran.Worked example
Which file do you change?
-
1
Priya's folder holds
greet.pyandguests.txt, a plain list of names. When she runsgreet.py, it printsHello, Ana!,Hello, Ben!and so on, one line per name inguests.txt. She wants it to sayWelcomeinstead ofHello. -
2change the instructions to change what the program does
WelcomeversusHellois about what the program does with every name, so it's an instruction. Instructions live in the source code,greet.py.change the instructions to change what the program does
-
3
She opens
greet.py, changes the quoted wordHellotoWelcome, and saves. The next time she runs it, every line starts withWelcome. -
4
If she'd wanted a new guest greeted, that's data. She'd add the name to
guests.txtand leavegreet.pyalone.
Worked example
Reading a program before running it
-
1
Before looking at the output, decide what this program prints.
print("Step 1: boil water") print("Step 2: add pasta") print("2 + 2")Step 1: boil water Step 2: add pasta 2 + 2 -
2
Start at the top. The first line prints
Step 1: boil water, then moves to a new line. -
3
The second line prints
Step 2: add pasta. -
4anything between the quotes is shown character for character
The third line looks like arithmetic, but it's between quotes, so it's just text.
printshows the five characters2 + 2exactly as typed and works nothing out.anything between the quotes is shown character for character
Check your understanding (counts toward your progress)
Lena's program reads names.txt and greets each person in it. She wants it to greet one extra person, Omar. What should she change?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
One program can greet any number of names. A copy isn't needed.
A file's name doesn't change what the program does or reads.
A program only knows what's in its instructions and the data it reads.
Why
The greeting steps are already right; only the list of people changes. That list is data, so the change goes in names.txt and the source code stays as it is.
Is Omar an instruction, or something the instructions work on?
Why can't the processor carry out hello.py as it is?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
A one-line .py file is just as unreadable to a processor. Size isn't the issue.
Any text editor opens a .py file. Opening isn't the problem; the processor understanding it is.
Running a Python file downloads nothing. The interpreter is installed once, ahead of time.
Why
A processor carries out tiny instructions stored as numbers. Python is text written for people, so the interpreter reads it and does what it says.
What form do a processor's instructions take?
Write the whole missing line so the program's last line of output is Goodbye.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
A line that shows text is print, round brackets, and the text inside double quotes: print("Goodbye").
Correct answer
Also accepted:
Why
Copy the shape of the two lines above it.
Fill the blank so the program's second line of output is exactly See you soon.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
print shows the text between the quotes exactly, so the blank holds See you soon with a capital S and nothing extra.
Correct answer
Also accepted:
Why
The quotes are already there. Type only what goes between them.
Practice: Programs, source code, and the interpreter (5 problems · doesn’t affect your progress)
Which of these is written by a person, for people to read and change?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Machine code is numbers for a processor. People don't write it anymore.
Output is produced by running the program, not written by hand.
Bytecode is made by the interpreter from your source.
Why
Source code is the readable text a person types. Everything else in the list is made from it, by the interpreter or by running it.
Source code
One line of output. What is it?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
One print, one line: the quoted text without its quotes.
Correct answer
Also accepted:
Why
Good morning
A packing list. Type what it prints.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Four lines, four outputs, top to bottom. Python doesn't skip a line because it printed the same text before.
Correct answer
Also accepted:
Why
Every line runs, even one that repeats.
Tent ⏎ Stove ⏎ Map ⏎ Tent
Fill the blank so the program prints Gate 4 and then Boarding now.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
The second line shows whatever is between its quotes, so the blank is Boarding now, capital B.
Correct answer
Also accepted:
Why
Boarding now
A program prints Total: 0 every time. The program is right, but the prices file it reads is empty. What needs fixing?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Typing prices into the program would only work for one list. The program is meant to read them.
Python ran the program correctly; it added up an empty list.
The total of nothing is 0, but that's not the total anyone wanted.
Why
The instructions are fine; they were given no data to work on. Fill the prices file and the same program prints the real total.
The data: put the prices in the file
Interpreted, compiled, and what CPython really does
Picture getting a speech across a language barrier. One way: have the whole speech translated in advance, printed, and handed out. Afterwards the listeners don't need the translator at all. The other way: bring a person who stands beside the speaker and turns each sentence into the listeners' language as it's spoken. Then the translator has to be there every time.
Programming languages come in roughly those two styles. In a compiled language, such as C++ or Rust, a translator program called a compiler works first. It turns your whole program into machine code (the number-steps the chip understands) before the program ever runs. It saves the result as a new file you can give to anyone with the same kind of computer, and they never need the translator.
Python works like the person at the speaker's side, so it's called an interpreted language. The interpreter (Python's step-following helper program) has to be there every time the program runs.
There's one honest wrinkle. Before Python's interpreter starts following your steps, it quickly reads the whole file and rewrites it into its own simpler step-by-step form, called bytecode. It does this every time you run the file, in a blink, and keeps it to itself. This explains a pattern you'll see constantly. If your file breaks Python's grammar anywhere, say a missing closing quote, nothing happens at all: the rewriting can't finish, so not even line 1 runs. A different mistake behaves differently. Say a line's grammar is fine, but you misspelled a word Python needs to look up. Python only notices when it reaches that line, and by then every line above it has already run.
There are two broad ways to get from source code to a running program. A compiled language, such as C++ or Rust, uses a translator called a compiler to turn the whole program into machine code ahead of time and save it as a separate file, an executable. Running is a later, separate step, and the person running the executable needs neither the compiler nor the source. An interpreted language hands the source to an interpreter each time the program runs, so the interpreter must be installed wherever the program runs.
Python is usually called interpreted, and for everyday purposes that's
right: you run the .py file itself, and nothing you could hand to a
friend is produced along the way. The fuller story is that CPython also
compiles, just not to machine code. Each time you run a file, it first
translates the whole file into bytecode, which it then carries out. Two
practical consequences follow. A mistake in the file's grammar anywhere
stops the run before any line has done anything, because the translation
step can't finish. A mistake that only shows up while the program is
carrying out a line (using a name Python doesn't know, say) is
discovered only when that line is reached, after every earlier line has
already run.
Compiled ahead of time, or interpreted?
Sort each card: does it describe a compiled language like C++ or Rust, or an interpreted one like Python?
Loading interactive…
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Correct answer
Also accepted:
Why
Why
.py file is run.Worked example
Sharing a finished program
-
1
Jonas wrote a small quiz game in Python,
quiz.py. His sister wants to play it on her laptop, which has never had anything for programming installed. -
2
Python is interpreted, so there's no finished machine-code file to send. The program is
quiz.py. He sends her that file. -
3the interpreter must be wherever the program runs
Double-clicking a
.pyfile on a computer without Python does nothing useful. She first installs Python (Chapter 1 shows how), then runspython quiz.pyand the game starts.the interpreter must be wherever the program runs
-
4
A friend of his who wrote the same game in Rust could send just the compiled executable instead. That file would run only on the kind of computer it was compiled for, which is the price of skipping the interpreter.
Worked example
Why a typo on line 3 stops line 1
-
1
Sam's file
main.pyshould print four lines, but line 3 is missing its closing quote.print("Starting the count") print("One") print("Two) print("Done")File "main.py", line 3 print("Two) ^ SyntaxError: unterminated string literal (detected at line 3) -
2
Nothing printed, not even
Starting the count. Before running anything, CPython reads the whole file to rewrite it as bytecode, and it can't get past line 3: an opening quote with no partner breaks Python's grammar. -
3a grammar mistake anywhere means no line runs
The report names the file and the line, prints that line, and puts a
^under the quote that never got closed. The last line says what kind of problem it is: aSyntaxError, Python's name for "this text doesn't follow the grammar". An unterminated string literal is a piece of quoted text that never ends.a grammar mistake anywhere means no line runs
-
4
Adding the missing
"afterTwofixes it, and all four lines print.
Check your understanding (counts toward your progress)
What is bytecode, in CPython?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Bytecode isn't machine code. Only the interpreter understands it.
It's a different form altogether, a list of small steps, not your text squeezed.
You never write bytecode. Python makes it from your file automatically.
Why
CPython translates your whole file into bytecode, small steps it knows how to follow, and then carries those out. You never write or need to read it.
Who makes it, and who reads it?
Sort each description: does it fit a compiled language like Rust, or Python?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
A compiler leaves a stand-alone executable, so the source and the compiler can stay behind. Python reads the .py file, translating it to bytecode, every time it runs, so the interpreter must be present.
Correct answer
Also accepted:
Why
Which style leaves behind a file that runs on its own?
A classmate says, "Python never compiles anything; it reads one line, runs it, then reads the next." What's the most accurate correction?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
If Python read one line at a time, a grammar mistake on the last line couldn't stop line 1 from running. It does.
No executable is made. The translation is to bytecode, kept inside the interpreter.
Lines are carried out top to bottom.
Why
CPython does compile, just not to machine code: it turns the whole file into bytecode first, then follows it. That's why a grammar mistake anywhere stops every line.
Think about what a syntax error on line 3 does to line 1.
Python is usually called an interpreted language. What does that mean in practice?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
That describes a compiled language such as C++ or Rust.
Python runs on ordinary computers, browsers aren't involved.
The interpreter has to be installed wherever a Python program runs.
Why
An interpreted program is carried out by the interpreter each time it runs, so the interpreter must be installed wherever it runs.
Does the helper program need to be there every time?
Practice: Interpreted, compiled, and bytecode (5 problems · doesn’t affect your progress)
What must be installed on any computer that runs a Python program?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Python programs aren't compiled to machine code ahead of time.
Any editor, or none, works; the interpreter is what runs the file.
A .py file can't run by itself.
Why
The interpreter reads and carries out the .py file, so it must be present wherever the program runs.
The Python interpreter
Put CPython's work on hello.py in order, from the moment you press Enter.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Read, check, translate, then carry out. The decoy describes a line-at-a-time reader, which isn't how CPython works: it handles the whole file before running any of it.
Correct answer
Also accepted:
Why
Sort each item: is it something you write, or something CPython makes or does for you?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
You write source code: the file and its lines. CPython checks it, translates it to bytecode, and carries out the steps.
Correct answer
Also accepted:
Why
You'd like to give a friend a program that runs with nothing installed on their computer. Which kind of language suits that best?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
A .py file needs the interpreter to run.
A compiled executable stands alone; a Python file doesn't.
A compiled executable runs without its source.
Why
A compiler leaves a stand-alone executable for one kind of computer. Python trades that for a single .py file that runs anywhere Python is installed.
A compiled one, such as Rust or C++
Challenge: a file's line 9 has an unclosed quote. Lines 1 to 8 are fine. How many lines print when you run it?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
That would be true for a runtime error. A grammar mistake stops the translation, so nothing runs.
Line 9 is broken; it can't print anything.
Speed has nothing to do with it; the order of steps is fixed.
Why
CPython translates the whole file before running any of it, and an unclosed quote stops the translation. No line runs.
None
When Python stops: before the run, or partway through
When Python can't go on, it stops and prints a report. There are two situations, and telling them apart tells you how far your program got.
The first is a syntax error. Syntax means the grammar rules of a
language: which symbols go where, which brackets pair up. Python checks the
whole file's grammar before it does anything, the way a teacher might scan
an essay for missing full stops before reading it for meaning. If the
grammar is broken anywhere, Python refuses to start. Your program prints
nothing at all. Python's report shows the file name, the line number, the
line itself with a small ^ arrow under the trouble spot, and a last line
starting with SyntaxError.
The second is a runtime error. Runtime means "while the program is
running". The grammar was fine, so Python started, and every line before
the bad one did its job, printing whatever it printed. Then Python reached
a line it couldn't carry out. Maybe a word was misspelled, so Python
looked it up and found nothing. Python stops right there and prints a
report it calls a traceback: a trail showing where the program was when
it stopped. Its last line names the kind of problem. Python 3.14 often adds
a friendly guess, like Did you mean: 'print'?.
Either way, read the report's bottom line first. That line says what went wrong. The lines above it say where.
Python reports a problem in one of two ways, and the difference tells you
how far the program got. A syntax error is found while CPython is
reading and translating the file, before any instruction runs. It prints
the file name and line, the offending line with a ^ under the spot, and
a last line beginning SyntaxError: (or IndentationError:) followed by a
description. Output from the program: none.
A runtime error happens while the program is running, at the line that
couldn't be carried out. Everything printed before that line stays on the
screen. Python then prints a traceback, its report of where the program
was when it stopped. It opens with the header
Traceback (most recent call last):, then gives the file, the line, and
the line itself with ^ marks under the part that failed. Its last line
names the kind of error, here NameError, which means "this name means
nothing to me". Python 3.14 often adds a suggestion such as
Did you mean: 'print'?. In both cases the program then ends, and nothing
after the failed line runs. Read the last line first: it says what went
wrong; the lines above it say where.
Here is a runtime error. The grammar of every line is fine; the problem is
that prnt isn't a word Python knows.
print("Starting the count")
print("One")
prnt("Two")
print("Done")
Starting the count
One
Traceback (most recent call last):
File "main.py", line 3, in <module>
prnt("Two")
^^^^
NameError: name 'prnt' is not defined. Did you mean: 'print'?
The first two lines printed, because Python had already carried them out
when it reached line 3. Done never printed, because a program stops at
its first runtime error. (The in <module> part means "in the main part of
the file"; Chapter 1 explains it.)
Bug hunt: which line stops everything?
This program has 1 mistake that stops Python before it prints anything. Click the broken line.
Loading interactive…
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Correct answer
Also accepted:
Why
Why
'(' was never closed and points at line 2.How far does it get?
Type exactly what appears before Python stops. Python 3.14 really ran this program; it ends in a NameError.
Loading interactive…
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Correct answer
Also accepted:
Why
Why
Print with a capital P. Python treats capital and small letters as different, so Print is a name it doesn't know: a runtime error. The program stops there, and Map never prints.Worked example
Reading a report from the bottom up
-
1
Sam runs a three-line
main.pyand gets this.print("Welcome back") print("You have 3 new messages" print("Goodbye")File "main.py", line 2 print("You have 3 new messages" ^ SyntaxError: '(' was never closed -
2
Bottom line first:
SyntaxError: '(' was never closed. It's a syntax error, so nothing ran, and the problem is an opening round bracket with no partner. -
3the
Now the location:
line 2, and the^sits under the(right afterprint. Count the brackets on that line: one(, zero).^marks where the trouble starts, which isn't always where the fix goesthe
^marks where the trouble starts, which isn't always where the fix goes -
4
The fix goes at the end of the line, not under the arrow: add
)after the closing quote, so it readsprint("You have 3 new messages"). Run it again and all three lines print.
Where this goes next
Chapter 1 §3 starts the interpreter by itself, at its >>> prompt. There
you type one line at a time and watch it answer. Chapter 1 §4 saves a
program like hello.py in a file and runs it with python hello.py. That's
the command this page keeps mentioning. Chapter 1 §8 is a full lesson on
reading Python's error reports, bottom line first. Chapter 9 §2 teaches you
to catch errors, so a program can recover instead of stopping.
Check your understanding (counts toward your progress)
Challenge: this program has 2 mistakes, one that stops it before it starts and one it would only meet mid-run. Click both broken lines.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Line 4's quote never closes, so Python refuses to start: nothing prints. Fix that, and line 2's prnt would still stop the run after Menu. Both lines need fixing.
Correct answer
Also accepted:
Why
Check every name, and check every quote has a partner.
Python's report ends with NameError: name 'pirnt' is not defined. Did you mean: 'print'?. Which line of the report should you read first?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
The top usually just says a report is starting. The kind of problem is named at the bottom.
Length tells you nothing. The bottom line names the problem.
The report is written for you, and its bottom line often even suggests the fix.
Why
Read the bottom line first: it names the kind of problem and often suggests a fix. The lines above it say where it happened.
Where does Python name the kind of problem?
Sort each situation: does Python stop before any line runs, or only when it reaches the problem line?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Missing quotes and brackets break the grammar, so Python refuses to start: a SyntaxError. A misspelled name is good grammar that fails only when Python tries to look it up: a NameError, after the earlier lines have run.
Correct answer
Also accepted:
Why
Is it a grammar problem, or a word Python can't look up?
This program runs its first two lines, then stops. Click the 1 broken line.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
The grammar is fine everywhere, so the first two lines run. Line 3 misspells print as pritn, which Python can't find, so the program stops there.
Correct answer
Also accepted:
Why
Some lines print, so the grammar is fine. Look for a misspelled name.
Practice: Before the run, or partway through (5 problems · doesn’t affect your progress)
Which kind of error means none of the program ran?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
A runtime error happens while the program is running, after earlier lines have run.
Only one of them is found before anything runs.
One of them is found before any line runs.
Why
A syntax error is found during the grammar check, before any line runs. A runtime error happens mid-run.
A syntax error
This program stops with a NameError. Type what appears before it stops.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Three good lines run. Line 4 misspells print, so the program stops there.
Correct answer
Also accepted:
Why
Step 1 ⏎ Step 2 ⏎ Step 3
This program prints nothing. Click the 1 broken line.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Line 3 opens a round bracket and never closes it. That's a grammar mistake, so not even Apples prints.
Correct answer
Also accepted:
Why
This program prints North, then stops. Fix it so all three directions print. It has 1 bug.
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
What this task checks
Structure checked automatically. Whether your ideas are convincing isn't graded, so reread with the checklist.
The compiler says
A model answer
Why
Print with a capital P is a name Python doesn't know. Making it print fixes the runtime error, and all three lines print.
Correct answer
Also accepted:
Why
Does Python see Print and print as the same name?
Python's report shows ^ under the ( after print on line 2, with SyntaxError: '(' was never closed. Where does the fix go?
Right on try — credit. Right — the answer had already been shown, so no credit this time. Next try is worth Answer shown after three tries — this one no longer earns credit. You chose to see the answer — this one earns no credit.
Removing the ( would break the line in a new way. The bracket needs a partner, not removal.
The report points at line 2, and line 1 is fine.
The bracket was opened on line 2, so it closes on line 2.
Why
The ^ marks where the trouble starts: the bracket that never closed. The fix is to add its partner ) at the end of that line.
At the end of line 2, where the missing ) belongs