Good place to stop if you're short on time — step 3 picks up here.
Lesson idea Tap to fold
Which file mode means read?
Show the answer
"r".
Write, close and verify a report
Writing is a side effect: it changes a file. A print on screen does not prove a report was saved. Close the write block, reopen the file and inspect its contents.
w replaces a report; a appends. Use w for the first write and a only when deliberately adding more text. Explicit UTF-8 keeps names portable between systems. Browser reports are temporary; use Download to request a computer copy before leaving or running again.
# Write, close and verify a report.
with open("report.txt", "w", encoding="utf-8") as file:
file.write("Museum · review\n")
with open("report.txt", "a", encoding="utf-8") as file:
file.write("Canal · approved\n")
with open("report.txt", encoding="utf-8") as file:
print(file.read(), end="")
The saved report contains both rows, each ending with a newline. end="" prevents print from adding a second final newline.
Inspect the report preview and download it if useful. A download request is not a course pass or confirmation that your browser saved the file.
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.
Choose a mode
A second w block opens the same report. What happens to the first block’s text?
Compare your answer · self-reviewed
It is replaced. Use a for an intentional append, and read back the result.
Separate evidence
Does printing a correct line prove the file contains that line?
Compare your answer · self-reviewed
No. Verify the saved file itself by reopening it.
Keep a copy
How does the browser report become a file you can keep?
Compare your answer · self-reviewed
Choose Download. The page requests a download but cannot confirm your browser saved it.
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.