Menu

Trace Tables

Output in Trace Tables

An output column records what an algorithm actually displays on screen. Each time a line prints something, you write the result in the output column of the row where that print happens — going down the table in the same order the algorithm produces it.

Copy the screen exactly

Write the output as it would look on screen, not as code. Quotation marks around string literals are not printed, so print('Goals scored') has the output column entry Goals scored — no quotes.

Spacing matters too. A comma inside print() adds a single space between the items, so with points holding 4, print('Goals scored:', points) shows Goals scored: 4. If you join strings with +, nothing is added, so 'Goals scored:' + str(points) shows Goals scored:4 all squashed together. Both are correct for their own line, so check which method the code uses before you write anything down.

for temp in [16, 21, 27, 30]:
    if temp > 24:
        print('Hot day:', temp, 'degrees')

Output:

Hot day: 27 degrees
Hot day: 30 degrees

Four values go round the loop, but only two of them pass the test and reach a print(), so the output column receives just two entries — written on the rows where the printing actually happened, not squeezed onto the first two rows. The values 16 and 21 were checked and rejected, so they never appear in the output column at all. The commas matter here too: print('Hot day:', temp, 'degrees') puts a space after the colon, giving Hot day: 27 degrees.

Only what is printed

It is tempting to fill the output column with the last value of every variable. Only values that reach a print() belong there. A variable that is calculated, tested or updated but never printed stays in its own column and nowhere else.

Worked example: an algorithm sets cost = 12, then cost = cost * 3, then tests if cost > 30 and prints Over budget. The output column gets one entry, Over budget, on the row where the condition is true. The value 36 stays in the cost column — even though the condition compares cost with 30, that 30 is never displayed. If the condition were false and nothing was printed, the output column would simply be left blank.

Practise this