Task 7 Resource

Trace table practice

Trace table and desk-check practice for loop and decision logic.

Back to resource pack

Task 7 Trace Table Practice

Trace tables help you test algorithm logic without guessing. They are especially useful for loops, counters and conditions.

How To Complete A Trace Table

  1. Write the variables as column headings.
  2. Add one row for the starting values.
  3. Step through the algorithm one instruction at a time.
  4. Update a variable only when the algorithm changes it.
  5. Record output only when the algorithm displays something.
  6. Check whether the final result matches what the program should do.

Worked Example

Algorithm:

balancedCount <- 0
FOR session <- 1 TO 3
  INPUT totalMinutes
  IF totalMinutes >= 30 AND totalMinutes <= 60 THEN
    balancedCount <- balancedCount + 1
  ENDIF
ENDFOR
OUTPUT balancedCount

Test data: 20, 45, 60.

session totalMinutes condition result balancedCount
start - - 0
1 20 false 0
2 45 true 1
3 60 true 2

Final output: 2

Practice Task 1

points <- 0
FOR question <- 1 TO 4
  INPUT correct
  IF correct = TRUE THEN
    points <- points + 2
  ELSE
    points <- points + 0
  ENDIF
ENDFOR
OUTPUT points

Test data: true, false, true, true.

question correct points
start -
1
2
3
4

Practice Task 2

attempts <- 0
INPUT rating
WHILE rating < 1 OR rating > 5
  attempts <- attempts + 1
  OUTPUT "Enter a value from 1 to 5"
  INPUT rating
ENDWHILE
OUTPUT attempts

Test data: 8, 0, 4.

step rating condition result attempts output
start - - 0
first input 8 true 0
after loop 1 0 true 1 Enter a value from 1 to 5
after loop 2 4 false 2 Enter a value from 1 to 5
final output 4 false 2 2

Practice Task 3

The program should count the number of scores that are 50 or above.

passCount <- 0
FOR item <- 1 TO 5
  INPUT score
  IF score > 50 THEN
    passCount <- passCount + 1
  ENDIF
ENDFOR
OUTPUT passCount

Test data: 50, 51, 49, 70, 30.

Questions

  1. Complete a trace table.
  2. Identify the logical error.
  3. Correct the condition.

Model Answer

The condition should include 50 because the requirement says 50 or above. The corrected condition is:

IF score >= 50 THEN

Attached Files

Task 7 downloads