Challenge 1: Write Then Read — Possible Solution ==================================================================== with open("output.txt", "w") as file: file.write("First line\n") file.write("Second line\n") file.write("Third line\n") with open("output.txt", "r") as file: for line in file: print(line.strip()) Output: First line Second line Third line WHY THIS WORKS AS AN ANSWER ------------------------------ The first with open("output.txt", "w") as file: block reuses the chapter's own "w" mode writing example exactly — three separate file.write() calls, each ending with an explicit \n newline character, since write() does not add line breaks automatically the way print() does. The file closes automatically the moment this with block ends, per the chapter's context-manager guarantee. The second with open("output.txt", "r") as file: block opens a BRAND NEW file handle in read mode, reusing the chapter's own line-by-line iteration pattern (for line in file:) rather than .read() or .readlines() — memory-efficient and directly demonstrated in the chapter's "Opening and Reading Files" section. .strip() on each line removes the trailing \n that was written into the file, reusing the exact same .strip() call the chapter's own reading example used — without it, each printed line would have an extra blank line after it from the leftover newline character. Two separate with blocks are used rather than one, because the first file must be fully written and closed before it can be reliably reopened and read — writing and reading the same file within a single open() call would require a different mode entirely (like "r+"), which this chapter doesn't cover.