Skip to content
ExamSpine

Lesson 5.7 · Trace it

Trace: grades

Python code8 rows to fill3 marks

Complete the trace table for this Python code. Then answer the question below the table. [3]

Line 1: scores = [45, 72, 90]
Line 2: grades = []
Line 3: for s in scores:
Line 4, indented 1 level: if s >= 80:
Line 5, indented 2 levels: grades.append("A")
Line 6, indented 1 level: elif s >= 60:
Line 7, indented 2 levels: grades.append("B")
Line 8, indented 1 level: else:
Line 9, indented 2 levels: grades.append("C")
Line 10: print(grades)

Fill in one row each time a line changes s or grades, or prints something. 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. In the output column, write exactly what appears on screen, with no quotes around it.

Rowsgradesoutput
1
2
3
4
5
6
7
8