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 | |
|---|---|---|
| 1Ava\nLiam\nMia | AA TXT file has no fields or data types, so it cannot store typed fields with headings. It only holds plain characters, usually one line per item. | |
| 2line = file.readline() # reads 88 | Bmark = int(file.readline()) | |
| 3A TXT file has no field headings, so the file does not label what each line means | CAva\n88\nLiam\n65 | |
| 4Because everything in a TXT file is read as a string, a number must be converted before it is used in a calculation | DA TXT file where each line holds one item, and the end of each line is marked by a newline character | |
| 5total = file.readline() + 10 | EThe line read from a TXT file is a string, so adding the integer 10 causes a type error. Convert it with int() first. | |
| 6Name: Ava, Mark: 88 stored in a TXT file as typed fields | FThe value read from a TXT file is the string '88', not the integer 88 |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
TXT file — A plain text file holds unformatted characters, usually one line of text per line ended by a newline. It has no field headings or data types, so everything is read as a string.f = open("names.txt", "w")
f.write("Ava\n")line = f.readline()
age = int(line)f = open("names.txt")
lines = f.readlines()line = f.readline()
name = line.strip()line = f.readline()
print(type(line) == str)