Good place to stop if you're short on time — step 3 picks up here.
Lesson idea Tap to fold
What does split("|") give you?
Show the answer
A list containing one item for each field between the separators.
Read text from a practice file
A text file stores a sequence of characters. Opening with w replaces its contents; opening with r reads an existing file. A with block closes the file even if the block fails.
These exercises create their own sample files inside a fresh browser workspace on each Run. They cannot read your computer’s files. A missing relative file raises FileNotFoundError; do not assume an earlier run created it.
# Read text from a practice file.
with open("names.txt", "w", encoding="utf-8") as file:
file.write("Museum\nCanal\n")
with open("names.txt", encoding="utf-8") as file:
names = file.read().splitlines()
for name in names:
print("Found:", name)
Found: Museum, then Found: Canal on a new line. splitlines removes line endings and preserves the row order.
Read the current file instead of replaying its visible sample. The checks provide unfamiliar contents at read time.
Predict, explain, then verify
These brief checks are self-reviewed, not quiz scores. Browser runs use fresh temporary files; they do not open your computer’s files. Download useful reports before another Run, Reset, exercise change or leaving.
Trace a read
What type does file.read() return, and what changes after splitlines()?
Compare your answer · self-reviewed
read returns a string. splitlines returns a list of row strings without their line endings.
Predict an error
What happens if r opens a relative file that this run never created?
Compare your answer · self-reviewed
FileNotFoundError. A fresh run does not inherit files from the previous attempt.
Locate the file
Does opening shots.txt in this page open a file on your computer?
Compare your answer · self-reviewed
No. It opens a temporary file in the browser Python workspace.
Choose an exercise to load its prompt.
Loading exercises…
Noted on your route map, with the step you were on. Nothing is lost by parking it — the next review day will bring this idea back, and the flag tells the course where to slow down.
The tutor mounts here when JavaScript is available. The lesson above stays readable without it.