All subjects · Computer Science · Unit 2
WCP02 Practical Programming and Problem-solving
Edexcel IAL Computer Science, Unit 2 (AS unit, usually Year 12). 36 lessons so far, in the suggested order.
Lessons in WCP02
- Sequence, input and output in Python
Sequence runs top to bottom; print() separates items with a space by default; input() always returns a string, so convert it with int() or float(). - Selection: if, elif, else and match
Only the first True branch of if/elif/else runs, so order the tests carefully; match/case compares one value against patterns, with case _ as the default. - Count-controlled iteration: for loops and range()
range(start, stop, step) never includes stop; loop over items directly or over range(len(items)) for indexes; initialise totals before the loop. - Condition-controlled iteration: while loops
while tests its condition before every pass; make sure the body changes something in the condition; use while for validation and searches with a found flag. - Exception handling with try and except
Put risky code in try and handle named exceptions in except, specific before general; know ValueError, TypeError, ZeroDivisionError, IndexError, KeyError, NameE - Variables and constants
= assigns the value on the right to the name on the left; identifiers are case-sensitive; constants are UPPER_CASE by convention and assigned once. - Arithmetic, relational and Boolean operators
/ always gives a float; // gives the whole-number quotient rounded down; % gives the remainder; and/or/not combine conditions with not before and before or. - Bitwise operators
& keeps bits set in both, | sets bits, ^ toggles bits, ~x = -x - 1, x << n multiplies by 2 to the power n, x >> n integer-divides by 2 to the power n. - Subprograms: functions, procedures, parameters and arguments
Functions return a value, procedures do not; parameters are the names in the definition, arguments the values in the call; return ends the function immediately. - Data types and type conversion
int, float, bool and str are the core types; a character is a one-character string; convert with int(), float(), str(), bool(); int() truncates; ord() and chr() - Arrays and lists in one and two dimensions
Lists are indexed from 0 and negative indexes count from the end; a 2D list is a list of rows accessed as grid[row][col]; build each row separately. - Records, dictionaries and tuples
A record is a list of mixed fields; a dictionary maps unique keys to values; a tuple is an immutable ordered group; convert with list(), tuple(), set(), dict(). - Numeric data: rounding, truncation and random numbers
round(x, n) rounds (halves go to even); int() and math.trunc() cut towards zero; math.floor() rounds down and math.ceil() up; random.randint(a, b) includes both - String handling: length, indexing, examining and manipulating
len(), indexing from 0 and slicing [a:b] (b excluded) work on strings; is...() methods examine, strip/lower/upper/split build new strings; strings are immutable - Formatting output with f-strings
In {value:spec}, < > ^ set alignment, a number sets the width, .n sets decimal places and s, d, f set the type; use matching widths for headings and rows. - Text files: open, read, write, append and close
Modes: "r" read, "w" write (erases), "a" append; close() every file; lines end in \n and are strings, so strip(), split(",") and convert. - Operations on data structures: create, insert, update, retrieve, delete, traverse
append/insert add, [i] = updates, [i] and get() retrieve, del and pop() remove, for loops traverse; do not delete during a for loop; b = a shares a list, deepco - Stacks: a fixed-length list with push and pop
LIFO: push and pop at the top; top starts at -1; full when top == MAX_SIZE - 1; check for overflow before push and underflow before pop. - Queues: a fixed-length list with enqueue and dequeue
FIFO: enqueue at the rear, dequeue from the front; in a fixed-length circular queue use (index + 1) % MAX_SIZE and a count to test empty and full. - Sets: membership, union, intersection and difference
Sets hold unique items with no order; in tests membership; | union, & intersection, - difference, ^ symmetric difference; use set() for an empty set. - SQLite in Python: creating tables and changing data
connect, cursor, execute, commit, close; CREATE TABLE with types and constraints; INSERT INTO, UPDATE ... SET ... WHERE, DELETE FROM ... WHERE; a missing WHERE - SQLite in Python: retrieving data with SELECT
SELECT fields FROM table WHERE condition ORDER BY field ASC/DESC; DISTINCT removes duplicates; fetchall() gives a list of tuples, fetchone() one tuple or None. - SQLite: filtering, aggregating and joining
AND/OR/NOT, BETWEEN (inclusive), LIKE with % and _, IS NULL; COUNT/SUM/AVG/MAX/MIN with GROUP BY and HAVING; INNER JOIN keeps matches only, LEFT JOIN keeps ever - Designing programs: decomposition, scope and side effects
Decompose into single-purpose subprograms; pass data in as parameters and out with return; avoid globals and hidden side effects; process data in as few passes - Modularity: subprograms, libraries and files
Use in-built subprograms and import libraries rather than rewriting them; know the four import forms; dates are ISO 8601 strings in UTC, converted with strptime - Clean code: consistency and readability
Consistent spacing, line breaks, naming and line length; meaningful identifiers, informative comments, named constants and well-named subprograms. - Controlling behaviour: boundaries, guard clauses and safe conversion
Test both sides of every boundary; use guard clauses to return early instead of deep nesting; convert types inside try/except at the point of input; avoid unnec - Testing, debugging, reviewing and refining
Syntax errors stop code running, runtime errors crash it, logic errors give wrong answers; test with normal, boundary and erroneous data; debug with messages, p - Computational thinking in code: abstraction, decomposition, patterns and generalisation
Abstraction: subprograms hide how; decomposition: plan the parts in a first comment; pattern recognition: reuse known solutions; generalisation: turn fixed valu - Turning algorithms in words and flowcharts into Python
Parallelogram: input/output; rectangle: process; diamond: if or loop condition; a back arrow: a loop. Initialise before loops, output after them, and do not pro - Linear search and its variations
Linear search checks items in order; worst case n comparisons; exit early when found; on a sorted list also exit as soon as an item is larger than the target. - Binary search: iterative and recursive
Binary search needs a sorted list; mid = (low + high) // 2; go left with high = mid - 1 or right with low = mid + 1; stop when found or low > high. - Bubble sort and its improvements
Bubble sort swaps adjacent items that are out of order; each pass fixes the largest remaining item; reduce the upper bound each pass and stop after a pass with - Insertion sort: the place-in algorithm
Save the target, shift larger items in the sorted section one place right, then put the target in the gap; outer loop from index 1; while j >= 0 and items[j] > - Recursion
A recursive subprogram needs a base case that stops it and a recursive case that moves towards it; calls wait on the call stack and unwind in reverse order. - Exam technique for the Unit 2 onscreen practical paper
3 hours, 80 marks, five compulsory questions in Python 3; save with the exact filenames; use supplied constants and code; make it work for any data; test it; wr
Next exams for WCP02
- Summer 2027: Mon 7 Jun 2027, morning, 3h 00m
From Pearson's final timetables. All exam dates. Always confirm your entries with your exams officer.