1
2
3
4
5
6
7
8
9
10
11
12
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to Trinket.
Post a review on Amazon for the paperback or the Kindle edition.
Email me to give me a compliment, complaint, or correction. I'll respond.
0,1,2,3,4,5,6,7,8,9,10,11
0
0
0
0
Call csv.reader. Make everything up. | contents = csv.reader(f) | ^ *[a-zA-Z_][a-zA-Z0-9_]* = csv\.reader\([a-zA-Z_][a-zA-Z0-9_]*\) *$ | |
Declare an empty list to hold the contents of the CSV file. Make up the name of the list. | file_contents = [] | ^ *[a-zA-Z_][a-zA-Z0-9_]* = \[\] *$ | |
Complete the fourth line. | 1 with open("cats.csv") as f: 2 cat_content = csv.reader(f) 3 cats_list = [] 4 for each_line in ___________ | cat_content: | cat_content`: |
Code the first line of the for loop that loops through CSV content returned by csv.reader. The CSV content is in the variable data. The variable this_line stores each line. Don't bother to indent. | for this_line in data: | for this_line in data: | |
Code the next line. Remember to indent it. Make up the name of the variable that stores each line. Start by indenting. | with open("competitions.csv") as f: contents = csv.reader(f) list = [] |
for a_line in contents: | ^ * for [a-zA-Z_][a-zA-Z0-9_]* in contents: *$ |
Code the next line. Start by double-indenting. | with open("competitions.csv") as f: contents = csv.reader(f) list = [] for a_line in contents: |
list += a_line | ^ * list \+= a_line *$ |
Code the next two lines. Make up the name of the variable that stores each line. Indent correctly. | with open("products.csv") as file_to_read: x = csv.reader(file_to_read) y = [] |
for z in x: y += z |
^ * for ([a-zA-Z_][a-zA-Z0-9_]*) in x:\n y \+= \1 *$ |
Code the missing line. Start by indenting. | with open("products.csv") as file_to_read: x = csv.reader(file_to_read) for z in x: y += z |
y = [] | ^ * y = \[\] *$ |
The file is open. The file handle is f. Code the next four lines. Make everything up. Start by indenting. | x = csv.reader(f) y = [] for z in x: y += z |
^ * ([a-zA-Z_][a-zA-Z0-9_]*) = csv\.reader\(f\)\n ([a-zA-Z_][a-zA-Z0-9_]*) = \[\]\n for ([a-zA-Z_][a-zA-Z0-9_]*) in \1:\n \2 \+= \3 *$ | |
Open a CSV file and read it. That's five lines of code. Make everything up. | with open("oceans.csv") as file_to_read: x = csv.reader(file_to_read) y = [] for z in x: y += z |
^ *with open\(•.+\.csv•\) as ([a-zA-Z_][a-zA-Z0-9_]*):\n ([a-zA-Z_][a-zA-Z0-9_]*) = csv\.reader\(\1\)\n ([a-zA-Z_][a-zA-Z0-9_]*) = \[\]\n for ([a-zA-Z_][a-zA-Z0-9_]*) in \2:\n \3 \+= \4 *$ | |
|
|||