Community resourceWorksheet

J277 2.2 Programming fundamentals consolidation

Part 5 of 5 · J277 2.2.3 · Applied programming

The final Paper 2 programming checkpoint, combining constructs, strings, arrays, records, files, subprograms, random numbers and SQL.

Students will:

  • select and combine techniques for an unfamiliar requirement
  • total a two-dimensional array
  • combine strings and random numbers in one program
  • debug faults in boundaries, accumulation and returns
  • justify the techniques chosen

Inside: 5 explanation cells, 3 runnable Python tasks, 2 multiple-choice questions and 4 written answers. 33 marks, about 60 minutes.

Series: J277 2.2.3 · Applied programming, part 5 of 5.

Shared by Coding PathwayVerified teacher

  • 14 cells
  • About 60 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026
  • Updated 9 Sept 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Programming fundamentals consolidation

This final Paper 2 programming worksheet combines core constructs with strings, arrays, records, files, subprograms and random numbers. It also revisits SQL as a separate written language. The aim is to select and combine techniques in unfamiliar but accessible contexts.

Key ideas to recall

  • A two-dimensional array stores values in rows and columns; nested loops can process every value.
  • A record groups named fields about one entity, and its fields may use different data types.
  • OCR file handling follows a clear sequence: open the required file, read or write the required data, then close the file after use.
  • An SQL query uses SELECT for fields (or * for all fields), FROM for the table and WHERE for conditions. AND requires both conditions to be true; OR requires either condition to be true.
  • Random generation must use the stated bounds, including the endpoints when the requirement says inclusive.
  • A function returns a result to its caller; an accumulator such as total or count must be updated rather than replaced on each match.
Multiple choice1 mark

A program must process every cell in a seating plan stored as rows and columns. Which structure is most directly suited to this?

  • AOne if statement
  • BNested loops over a two-dimensional array
  • CA record with one field
  • DBinary search without sorted data

Integrated practice: select fields from a two-dimensional array

The two-dimensional array sessions represents a table. In each row, index 0 stores a day code, index 1 stores a room number and index 2 stores the duration in minutes. Each row therefore represents one session.

Complete total_minutes(sessions, target_day) so it returns the total duration of sessions whose day code matches target_day. Loop through the rows, compare the field at index 0 and add the field at index 2 when it matches. You do not need to visit every individual field with a nested loop.

Replace pass with the algorithm. Do not print or hard-code the supplied answer because the checks will call the function with different data.

Coding task6 marks
# Return the total duration for sessions on target_day.
def total_minutes(sessions, target_day):
    pass

answer = total_minutes([
    [1, 12, 30],
    [2, 15, 20],
    [1, 18, 25]
], 1)
Written answer3 marks

A program receives score and filename. Describe the OCR file-handling operations needed to write the score as a line in the supplied file.

Start by opening the filename parameter. Use the resulting file variable for the remaining operations.

Students type their answer here.

Multiple choice1 mark

Which SQL query returns Name and Points from table Players where Points is at least 100?

  • ASELECT Name Points FROM Players IF Points > 100
  • BFROM Players SELECT Name, Points WHERE Points = '100'
  • CSELECT Name, Points FROM Players WHERE Points >= 100
  • DSELECT Players FROM Name, Points WHERE >= 100

Integrated practice: strings and random numbers

Build a six-character challenge code. Its first four characters must be the slice team[0:4]; its final two characters must be independently generated digits from 0 to 9 inclusive.

Convert both random integers to strings before concatenation and store the result in code. The exact code is unpredictable, so the checks examine its length, prefix and digit characters rather than expecting one fixed answer.

Coding task4 marks
# Build a six-character challenge code from two random digits and the first four characters of team.
import random
team = "Falcons"
# Each random digit must be from 0 to 9 inclusive.
Written answer5 marks

A student record contains student_id, name, year_group and present. State a suitable data type for each field and justify the type for present.

Use OCR data-type names. An identifier is not necessarily used for arithmetic.

Students type their answer here.

Debugging challenge: boundary, accumulation and return

The supplied function should return how many values are at least limit, but it contains three logic errors. Compare the code carefully with that requirement. Pay particular attention to whether the boundary is included, how the count changes after each match and whether the calculated result is sent back to the caller.

Correct all three errors. The supplied call should return 3, and the checks will also test a list containing no matches.

Coding task4 marks
# Debug this function so it returns the number of values at least limit.
def count_at_least(values, limit):
    count = 0
    for value in values:
        if value > limit:
            count = 1
    print(count)

answer = count_at_least([4, 7, 7, 9], 7)
Written answer3 marks

Explain the three logic errors corrected in count_at_least and how each correction changes the program's behaviour.

Discuss the boundary comparison, accumulation and the difference between print and return.

Students type their answer here.

Written answer6 marks

Plan three tests for count_at_least: one where some values are greater than the limit, one containing a value exactly equal to the limit, and one where no values meet the limit. Give the input list, limit and expected result for each test.

Use small lists whose expected counts can be checked by inspection. Make sure the three cases are different.

Students type their answer here.

Paper 2 programming checkpoint

Before submitting a program, check the requested inputs, outputs and return values; all inclusive and exclusive boundaries; loop termination; array indices; indentation; and whether normal, boundary and exceptional cases behave as intended. Partial, well-directed solutions can earn exam marks, so write the parts you can solve clearly.