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 | |
|---|---|---|
| 1','.join(record) | Afile.write('name,mark\n') | |
| 2str(record[2]) | BJoins the string fields of a record into one comma-separated line ready to write to a CSV file | |
| 3Write a header row first so the CSV file has column names, then the data lines | CNo newline is added, so every record ends up on the same line. Add + '\n' after the joined text. | |
| 4Append a new record to the end of an existing CSV file without erasing the old lines | DConverts a number field to a string so it can be joined into a CSV line | |
| 5line = ','.join(['Ava', 88]) | Eopen('marks.csv', 'a') | |
| 6file.write(','.join(record)) | FThe number 88 is not a string, so join() causes a TypeError. Use str(88) first. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
','.join(record) — Joins a record's fields, which must all be strings, into one comma-separated line. Use str() on numbers first, then write the line plus a newline to the CSV file.line = ','.join(record)line = ','.join([name, str(score)])row = [name, str(score)]
f.write(','.join(row) + '\n')with open('scores.csv', 'a') as f:
f.write(','.join(row) + '\n')header = ','.join(['Name', 'Score'])
f.write(header + '\n')