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 | |
|---|---|---|
| 1with open('f.txt','w') as f: f.read() | AValid: Lines as a list | |
| 2with open('f.txt') as f: f.read() f.read() | BOutput: Hi | |
| 3with open('f.txt') as f: lines = f.readlines() | CError: Second read returns empty | |
| 4with open('f.txt') as f: for line in f: print(line.strip()) | DOk: Loop line by line | |
| 5# file has 'Hello\nWorld' f.readline() | EOutput: 'Hello\n' | |
| 6# file has 'Hi' print(f.read()) | FError: Can't read in write mode |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
.read() — Reads the entire file as one string.~~.readline()with open('f.txt') as f:
content = f.read()
print(content)with open('f.txt') as f:
lines = f.readlines()with open('f.txt') as f:
first = f.readline()for line in f:
print(line.strip())with open('f.txt') as f:
for line in f:
print(line)