Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1print("total:", total) | ASyntax error: a comma is missing between the text and the variable, so Python stops with an error before running | |
| 2print("in add(): a =", a, "b =", b) | BShows the current value of total at this point so you can compare it with your trace table | |
| 3A trace table says total should be 6 after the loop, so print total after the loop to check it | CLogic error: total = n replaces the value instead of adding to it. Printing after the loop would show 3 when the trace table expects 6 | |
| 4A logic error: the program runs without crashing but gives the wrong answer, like adding 1 instead of 2 | Dprint("after loop:", total) | |
| 5print("total:" total) | Ecount = count + 1 | |
| 6total = 0 print("total:", total) for n in [1, 2, 3]: total = n | FPrints inputs inside one function so you can test that function on its own and narrow down the bug |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
print(variable) — Debugging tool: print a variable at key points, then compare each value with your trace table of what it should be. The first mismatch shows where the bug is.total = 0
total = total + 5
print(total)for i in range(3):
total = total + i
print("total:", total)total = 30
average = total / 3
print(average)def add(a, b):
return a + b
print(add(2, 3))def double(n):
print("n is", n)
return n * 2