OCR GCSE Computer Science (J277) · Paper 2

⌨️ Programming

Revision notes written to the specification, with examiner tips and the required practicals. Every point here has flashcards in the Stickwise app.

Fundamentals & data structures

Three constructs build every program: sequence, selection (if/elif/else) and iteration, where a for loop is count-controlled and a while loop is condition-controlled. Values are stored in variables or constants, typed as integer, real, Boolean, character or string. Because keyboard input always arrives as a string, any maths on it needs casting first, for example int(input()). Random numbers, generated with something like random(1,6), power dice rolls, shuffles and simulations.

OperatorsComparison operators are ==, !=, <, <=, > and >=, and arithmetic operators are +, −, *, / and ^. MOD gives the remainder after division, so 17 MOD 5 = 2. DIV gives the whole number of times one number divides into another, so 17 DIV 5 = 3.
Strings (positions from 0)Strings are indexed from position 0. "Stickwise" has a length of 9, and substring(0,5) returns "Stick". "Stick"+"wise" concatenates the two strings together. Other string operations include converting to upper or lower case, and converting between characters and their codes with ASC and CHR.
ArraysAn array stores many values under one name, in indexed slots. A 2D array is a grid, indexed as board[row][column].
Sub programsA procedure runs a set of instructions, while a function returns a value; both can take parameters. Using them avoids repeated code and breaks a program into testable pieces.
FilesWorking with a file means opening it, reading or writing its lines, and then closing it, or data can be lost.
Databases & SQLA record is a row in a database table, representing one entry, and a field is a column, representing one property. For example, SELECT name, age FROM students WHERE age > 15 selects columns from a table and filters the rows; using * instead of column names selects all fields.

Robust programs & testing

Defensive design means assuming things will go wrong. Validation checks the data itself: its presence, type, range, format and length. Authentication checks the person, through passwords with lockouts, 2FA and biometrics. Good design anticipates misuse, such as dividing by zero, typing 'banana' where a number is expected, leaving inputs empty, or mashing buttons, and handles all of it with polite error messages rather than crashing. Maintainability comes from comments, sensible indentation, honest variable names and sub programs, since code is really a letter written to the next programmer.

A syntax error breaks the rules of the language and stops the program running at all, whereas a logic error lets the program run but gives the wrong answer. Testing should happen iteratively while the program is being built, and terminally once it is finished, using normal, boundary, invalid and erroneous data, since programs tend to fail at the edges and on the inputs nobody expected.

Boolean logic, languages & IDEs

ANDboth 1 → 1ORany 1 → 1NOTflips the input2 inputs = 4 truth-table rows (00 01 10 11) — AND lights only 11; OR all but 00

Read a logic circuit left to right, bracketing each gate in turn: if A and B feed into an AND gate, and the result is joined with C at an OR gate, the expression is P = (A AND B) OR C, with the brackets showing which gate fires first. High-level languages are English-like and portable but need translating, while low-level languages, such as assembly and machine code, are the CPU's own language. A compiler translates the whole program at once, giving a fast final product and a full list of errors, and can be distributed on its own; an interpreter translates line by line, starting instantly but halting at the first error, which makes it well suited to learning. An IDE bundles together a smart editor, a run-time environment, error diagnostics and breakpoints.

Turn these notes into memory. 29 flashcards cover this topic. Short daily sessions, spaced repetition up to your exam date, quizzes with friends. Free during the beta.Practise Programming in the app ↗