Skip to content
ExamSpine

Trace it

Trace table: best score from file lines

Python code12 rows to fill5 marks

Complete the trace table for this Python code. lines holds the three lines already read from a file scores.csv, with the line breaks removed. split(",") cuts a line at each comma into separate strings. Each value of parts is shown in square brackets, like ['Zoe', '3']. Then answer the question below the table. [5]

Line 1: lines = ["Ana,12", "Ben,7", "Cal,15"]
Line 2: best = ""
Line 3: top = 0
Line 4: for line in lines:
Line 5, indented 1 level: parts = line.split(",")
Line 6, indented 1 level: score = int(parts[1])
Line 7, indented 1 level: if score > top:
Line 8, indented 2 levels: top = score
Line 9, indented 2 levels: best = parts[0]

Fill in one row each time a line changes parts, score, top or best. The table already has the right number of rows. In each row, write only what that line changes; you can leave the other cells empty or copy their values down. Write values the way Python shows them: 3 and 3.0 are different, and text goes in quotes.

Rowpartsscoretopbest
1
2
3
4
5
6
7
8
9
10
11
12

Report a problem with this page