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 | |
|---|---|---|
| 1for line in open("readings.csv"): | AReads a file as a stream, giving the program one line (one record) at a time | |
| 2for reading in sensor_feed: | BThe loop replaces total with each reading instead of adding to it, so nothing builds up as the stream flows. The code should use total = total + reading, after setting total to 0 before the loop. | |
| 3A stream is processed one record at a time, so a loop handles each record in turn | CProcesses sensor readings one record at a time as they arrive | |
| 4API results can be treated as a stream of records, with each result processed as it is read | Dread() loads the whole file into one string, so the loop gets single characters instead of lines. It no longer treats the file as a stream of records. | |
| 5data = open("readings.csv").read() for line in data: | Efor record in stream: print(record) | |
| 6for reading in sensor_feed: total = reading print(total) | Ffor result in api_results: process(result) |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
stream — A sequence of structured records that arrives or is read one at a time, such as sensor readings, file lines or API results, and is processed as it flows.for reading in sensor_stream:
print(reading)for line in open("log.csv"):
print(line)for record in api_results:
print(record)total = 0
for r in readings:
total = total + r["temp"]for line in open("data.csv"):
fields = line.split(",")
print(fields[0])