Python · GCSE 7
Trace Tables and Debugging
Name
Class
Date
Mark / 26
Section A
Circle the letter of the correct answer. One mark each.
- 1What does a trace table record?1
- AThe errors the translator found, together with their line numbers
- BThe names of every subprogram and where each one is called from
- CThe time each line takes to run, so slow lines can be found
- DThe value of each variable after every step of an algorithm
- 2
x = 1, theny = 10, thenwhile y > 4:withx = x * 2andy = y - 3inside. What isxat the end?1- A1
- B2
- C4
- D8
- 3What does
number % 10give for4721?1- A1
- B4
- C10
- D472
- 4A function adds up a list but has its
returninside the loop. What does it return for[1, 2, 3]?1- ANone
- B3
- C6
- D1
- 5A program finds the largest number by starting
largest = 0. For which list does it give the wrong answer?1- AA list with one item
- BA list with ten items
- CA list of only positive numbers
- DA list of only negative numbers
- 6Which of these is a syntax error?1
- AUsing
>instead of>= - B
if x = 5: - CAdding 1 instead of 2 each time
- DStarting a loop at 1 instead of 0
- AUsing
- 7What does a breakpoint do?1
- ADeletes the line
- BSpeeds the program up
- CPauses the program at a chosen line
- DReports every error in the program
- 8What does a variable watch show?1
- AA list of all the variables in the language
- BThe current value of a variable while the program is paused
- CHow long a variable has existed
- DThe memory address of the program
- 9What is the best description of the purpose of a loop that keeps taking
a MOD buntilbis 0?1- AIt finds the highest common factor of two numbers
- BIt sorts two numbers into ascending order
- CIt counts how many times one number goes into another
- DIt finds the lowest common multiple of two numbers
- 10Which is the most useful first step when a program gives an error message?1
- ARead the last line and the line number
- BAdd more comments
- CRun it again until it works
- DDelete the line it mentions
Section B
Answer in the space provided. The number of marks tells you how many separate points to make.
- 1CompleteThe program shown is run. Complete the values of x and y after each pass of the loop, and state the value that is output.3Python
x = 1 y = 10 while y > 4: x = x * 2 y = y - 3 print(x) - 2StateThe algorithm shown is run with a = 48 and b = 18. State what the algorithm does, and the value it outputs.3Python
a = 48 b = 18 while b != 0: temp = b b = a % b a = temp print(a) - 3IdentifyThe program is meant to display the largest number in the list. Identify the error, explain what output it gives for this list, and write a corrected version of the line.4Python
numbers = [-4, -9, -2, -7] largest = 0 for n in numbers: if n > largest: largest = n print(largest) - 4NameThe line shown is part of a program and it stops the program from running. Name the type of error and write the corrected line.2Python
score = 7 if score = 7: print("Seven") - 5DescribeDescribe two features of an integrated development environment (IDE) that help a programmer to find and correct errors.4
Mark scheme
Section A
Section B
1 The program shown is run. Complete the values of x and y after each pass of the loop, and state the value that is output. 3
One mark for each of the following, to a maximum of 3.
- x is 2 and y is 7 after the first pass
- x is 4 and y is 4 after the second pass, and the loop then stops because 4 is not greater than 4
- The value output is 4
Model answer. After the first pass x is 2 and y is 7. After the second pass x is 4 and y is 4. The condition y > 4 is now false, because 4 is not greater than 4, so the loop stops without a third pass, and the value output is 4.
2 The algorithm shown is run with a = 48 and b = 18. State what the algorithm does, and the value it outputs. 3
One mark for each of the following, to a maximum of 3.
- It finds the highest common factor of the two numbers
- Of a and b, or 48 and 18
- The value output is 6
Model answer. The algorithm finds the highest common factor of the two numbers, which is the largest whole number that divides exactly into both. For 48 and 18 the values of b are 18, 12, 6 and 0, and the algorithm outputs 6.
3 The program is meant to display the largest number in the list. Identify the error, explain what output it gives for this list, and write a corrected version of the line. 4
One mark for each of the following, to a maximum of 4.
- largest is set to 0 before the loop
- All the numbers in the list are negative, so none is greater than 0
- The program outputs 0, which is not in the list
- The corrected line is largest = numbers[0]
Model answer. The error is that largest starts as 0. Every number in the list is negative, so none of them is greater than 0, the test never succeeds, and the program outputs 0, which is not in the list at all. The line should be largest = numbers[0], so the comparison starts from a value that really is in the list. The correct output is -2.
4 The line shown is part of a program and it stops the program from running. Name the type of error and write the corrected line. 2
One mark for each of the following, to a maximum of 2.
- It is a syntax error
- The corrected line is if score == 7:
Model answer. This is a syntax error. A single equals sign assigns a value, and a comparison needs two, so the line should read if score == 7: and the program can then run.
5 Describe two features of an integrated development environment (IDE) that help a programmer to find and correct errors. 4
One mark for each of the following, to a maximum of 4.
- A breakpoint pauses the program at a chosen line
- So the programmer can inspect the state, or step through one line at a time
- Error diagnostics highlight the line with a fault and describe the problem
- So the programmer is taken straight to the fault without searching
Model answer. A breakpoint pauses the program at a line chosen by the programmer, so the values of the variables can be inspected, and the program can then be stepped through one line at a time to see exactly where the values stop being what was expected. Error diagnostics highlight the line containing a fault and describe the problem, so the programmer is taken straight to where it is rather than having to search the whole program for it.