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.

Practise this unit in the app: instant marking and a fix for every mistake. Free, no email needed to start.

Practise in the app

Lessons in WCP02

  1. 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().
  2. 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.
  3. 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.
  4. 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.
  5. 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
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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()
  11. 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.
  12. 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().
  13. 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
  14. 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
  15. 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.
  16. 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.
  17. 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
  18. 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.
  19. 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.
  20. 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.
  21. 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
  22. 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.
  23. 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
  24. 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
  25. 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
  26. Clean code: consistency and readability
    Consistent spacing, line breaks, naming and line length; meaningful identifiers, informative comments, named constants and well-named subprograms.
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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.
  32. 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.
  33. 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
  34. 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] >
  35. 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.
  36. 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

From Pearson's final timetables. All exam dates. Always confirm your entries with your exams officer.