Be precise, and amend with care
An algorithm must say exactly what to do. 'More than 50' is `> 50`. '50 or more' is `>= 50`. These give different results for 50.
Set every total, counter, highest and lowest to a start value before the loop. Use meaningful names like `PassCount`, not `x`, and `//` comments.
An amend question asks you to change a given algorithm. Find the line that controls the behaviour and change only that line.
Example: to make the bubble sort give descending order (largest first), change `>` to `<` in the comparison.
e.g.Example7, 3, 9, 2, 5 sorted with the amended line:
Output: 9, 7, 5, 3, 2
// Original: sorts into ascending order (smallest first)
IF Numbers[Index] > Numbers[Index + 1]
// Amended: sorts into descending order (largest first)
IF Numbers[Index] < Numbers[Index + 1]
numbers = [7, 3, 9, 2, 5]
top = 5
swap = True
while swap == True and top > 1:
swap = False
for index in range(top - 1):
# amended: < instead of > gives descending order
if numbers[index] < numbers[index + 1]:
temp = numbers[index]
numbers[index] = numbers[index + 1]
numbers[index + 1] = temp
swap = True
top = top - 1
print(numbers)?Why?Rewriting the whole algorithm wastes time and can add new errors. The examiner is looking for the one or two key changes.
!Watch out`Days >= 1 AND <= 21` is wrong. Write the variable on both sides: `Days >= 1 AND Days <= 21`.
The 15-mark scenario question: plan first
The last question on Paper 2 is a scenario worth 15 marks. Allow about 30 minutes. You may answer in pseudocode, Python, Visual Basic or Java.
Read the scenario twice. Underline every task. Make a numbered checklist and tick each item as you code it.
Sample scenario: a teacher records three tests for each of 30 students. Each test is out of 50. Names are already in `StudentName[1:30]`.
e.g.ExampleTasks in the sample scenario:
1. Input three marks per student and store them in StudentMark[1:30, 1:3].
2. Validate each mark: 0 to 50.
3. Calculate and store each student's total in StudentTotal[1:30].
4. Calculate each student's average, rounded to 1 decimal place.
5. Output each name with total and average.
6. Count and output the students with a total of 120 or more (a merit).
7. Output the class average total and the name of the student with the highest total.
All inputs and outputs need suitable messages.
?Why?Marks are given for meeting each requirement. A checklist stops you forgetting one, which is the most common way to lose marks here.
Model answer in pseudocode and Python
The model answer uses two nested `FOR` loops: one for students, one for tests. It reuses validation, totalling, counting, maximum and average.
Read the comments. They say what each part does, which also earns marks.
Python lists start at index 0, so the Python loops use `range(30)` and `range(3)`.
The first Python line is a stand-in for the names, so the program can run. In the exam you do not write it, because the names are already stored.
e.g.ExampleIf one student scores 45, 40 and 38:
Total = 45 + 40 + 38 = 123. Average = 123 Γ· 3 = 41.0
123 >= 120, so MeritCount goes up by 1.
If 123 is more than TopTotal, TopTotal becomes 123 and TopStudent becomes this student's index.
Python sample run:
Enter mark for test 1 for Student 1: 55
Error: a mark must be from 0 to 50. Enter it again: 31
// StudentName[1:30] already holds the 30 names
DECLARE StudentName : ARRAY[1:30] OF STRING
DECLARE StudentMark : ARRAY[1:30, 1:3] OF INTEGER
DECLARE StudentTotal : ARRAY[1:30] OF INTEGER
DECLARE Student : INTEGER
DECLARE Test : INTEGER
DECLARE Mark : INTEGER
DECLARE Total : INTEGER
DECLARE Average : REAL
DECLARE ClassTotal : INTEGER
DECLARE MeritCount : INTEGER
DECLARE TopTotal : INTEGER
DECLARE TopStudent : INTEGER
// set the class totals and counters to their start values
ClassTotal β 0
MeritCount β 0
TopTotal β -1
TopStudent β 1
FOR Student β 1 TO 30
Total β 0
FOR Test β 1 TO 3
// input one mark and validate it with a range check (0 to 50)
OUTPUT "Enter mark for test ", Test, " for ", StudentName[Student]
INPUT Mark
WHILE Mark < 0 OR Mark > 50 DO
OUTPUT "Error: a mark must be from 0 to 50. Enter it again"
INPUT Mark
ENDWHILE
// store the valid mark and add it to this student's total
StudentMark[Student, Test] β Mark
Total β Total + Mark
NEXT Test
// store the total, work out the average and output the results
StudentTotal[Student] β Total
Average β ROUND(Total / 3, 1)
OUTPUT StudentName[Student], " Total: ", Total, " Average: ", Average
ClassTotal β ClassTotal + Total
// a total of 120 or more earns a merit
IF Total >= 120
THEN
MeritCount β MeritCount + 1
ENDIF
// remember the highest total so far and whose it is
IF Total > TopTotal
THEN
TopTotal β Total
TopStudent β Student
ENDIF
NEXT Student
// whole-class results
OUTPUT "Class average total: ", ROUND(ClassTotal / 30, 1)
OUTPUT "Number of merits: ", MeritCount
OUTPUT "Highest total: ", StudentName[TopStudent], " with ", TopTotal# The question says the names are already stored.
# This line is a stand-in so the program can run.
student_name = ["Student " + str(n) for n in range(1, 31)]
student_mark = [[0, 0, 0] for row in range(30)]
student_total = [0] * 30
# set the class totals and counters to their start values
class_total = 0
merit_count = 0
top_total = -1
top_student = 0
for student in range(30):
total = 0
for test in range(3):
# input one mark and validate it with a range check (0 to 50)
mark = int(input("Enter mark for test " + str(test + 1) + " for " + student_name[student] + ": "))
while mark < 0 or mark > 50:
mark = int(input("Error: a mark must be from 0 to 50. Enter it again: "))
# store the valid mark and add it to this student's total
student_mark[student][test] = mark
total = total + mark
# store the total, work out the average and output the results
student_total[student] = total
average = round(total / 3, 1)
print(student_name[student], "Total:", total, "Average:", average)
class_total = class_total + total
# a total of 120 or more earns a merit
if total >= 120:
merit_count = merit_count + 1
# remember the highest total so far and whose it is
if total > top_total:
top_total = total
top_student = student
# whole-class results
print("Class average total:", round(class_total / 30, 1))
print("Number of merits:", merit_count)
print("Highest total:", student_name[top_student], "with", top_total)?Why?The Python version was run with 90 test marks, including invalid ones, to check it works. In Python, `round(total / 3, 1)` keeps one decimal place; `//` would cut off the decimals.
!Watch outStore values in the arrays the question names. Calculating the total but not storing it in StudentTotal loses marks.
How the 15 marks are awarded
Recent mark schemes use levels, not one mark per line. AO2 (applying techniques and data structures) gives up to 9 marks. AO3 (comments, identifiers, logic and accuracy) gives up to 6 marks.
The examiner reads the whole answer and picks the band that fits best. Minor syntax errors are ignored if the logic is clear.
e.g.ExampleThe model answer reaches the top bands because it:
- inputs with messages and validates every mark (input, iteration, selection)
- stores marks in the 2D array and totals in StudentTotal (data structures)
- uses totalling, counting, maximum, average and ROUND
- outputs every result with a message
- has a comment for every section and meaningful names like MeritCount
?Why?Because marks come in bands, a working answer to every task beats a perfect answer to half of them. Attempt every requirement, even if one part is rough.