Skip to content
ExamSpine

Lesson 5.1 · Trace it

Trace: char at

Python code5 rows to fill4 marks

Complete the trace table for this Python code. word[i] is the character at index i, counting from 0, and len(word) is the number of characters. [4]

Line 1: word = "code"
Line 2: i = 1
Line 3: a = word[i]
Line 4: i = len(word) // 2
Line 5: b = word[i]
Line 6: print(a + b)

Fill in one row each time a line changes i, a or b, 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.

Rowiaboutput
1
2
3
4
5