Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1f.close() | Aclose is missing its brackets so it never runs, and write() is called after the file should be closed. Use f.close() after the last write. | |
| 2with open("scores.txt", "w") as f: | Bf.close() f = open("scores.txt", "r") | |
| 3After writing to a file, close it so the data is saved and the file is released | CEnds access to the open file, saves any written data and releases the file | |
| 4A file can be reopened after it has been closed, by calling open() again | DThe file is never closed, so the written data may not be saved and the file stays locked. Add f.close() after writing. | |
| 5f = open("log.txt", "w") f.write("Saved") | EOpens the file and closes it automatically when the indented block ends | |
| 6f.close f.write("Done") | Ff.write("Ava,88") f.close() |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
file.close() — Ends access to an open file so any written data is saved and the file is released. Forgetting it can lose data. A with statement closes the file for you automatically.f = open("scores.txt", "w")
f.write("Ava,88")
f.close()with open("log.txt", "w") as f:
f.write("Saved")f = open("data.txt", "w")
f.close()
f = open("data.txt", "r")f = open("notes.txt", "a")
f.write("Done")
f.close()f = open("scores.txt", "w")
f.write("Ava,88")
f.close()