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 = open('data.txt') print(f.read()) f.write('hi') | AOk: Append mode — adds to end | |
| 2open('missing.txt', 'r') | BError: FileNotFoundError | |
| 3with open('f.txt', 'r') as f: data = f.read() | CValid: with auto-closes file | |
| 4open('f.txt', 'a') | DOutput: (writes 'Hi' to file) | |
| 5with open('f.txt','w') as f: f.write('Hi') | EError: Can't write in read mode | |
| 6f = open('f.txt','r') print(type(f)) | FOutput: <class '_io.TextIOWrapper'> |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
open() — Built-in function that opens a file.~~'r' modewith open('file.txt', 'r') as f:with open('file.txt', 'r') as f:with open('file.txt', 'w') as f:with open('log.txt', 'a') as f:
f.write('entry')f = open('test.txt', 'w')
f.write('Hi')
f.close()