What programming fundamentals covers
This topic is the bread and butter of Edexcel GCSE CS Component 2: writing, tracing and fixing pseudocode/code (usually Python-style). You need to know data types, variables, operators, sequence, selection, iteration, string handling, and how to trace through code by hand.
Data types
- Integer (int) - whole numbers, e.g. 7
- Real/float - decimals, e.g. 7.5
- Boolean - True or False only
- Character - a single letter/symbol
- String - a sequence of characters, e.g. 'hello'
- Casting converts between types, e.g. int('5') turns text into a number - a very common exam trap when input() is used, since Python input is always read as a string first.
Variables and constants
- A variable can change value while the program runs; a constant stays fixed.
- Use meaningful identifier names - exam mark schemes reward this in extended-writing questions.
- Assignment uses = ; comparison uses == . Mixing these up is the single most common beginner error.
Operators
- Arithmetic: + - * / (division, gives a float) // (integer/floor division) % (modulus, gives the remainder) ^ or ** (exponent, depending on notation used)
- Comparison: == != > < >= <=
- Boolean/logical: AND, OR, NOT - know truth tables for all three.
Sequence, selection, iteration
- Sequence: instructions run top to bottom in order.
- Selection: IF / ELSE IF / ELSE for branching decisions.
- Iteration: FOR loops (count-controlled, you know the number of repeats in advance) and WHILE/REPEAT-UNTIL loops (condition-controlled, used when you don't know the number of repeats in advance). WHILE checks the condition before running; REPEAT-UNTIL checks after, so it always runs at least once.
String handling
- Concatenation joins strings with +.
- len() finds the length.
- Substrings/slicing extract part of a string - remember indexing starts at 0, not 1.
- .upper() and .lower() change case.
Common mistakes examiners flag
- Off-by-one errors in loops (using <= instead of < or starting counts at the wrong number).
- Forgetting that array/list indices start at 0.
- Confusing = with ==.
- Not initialising a variable (e.g. a total or counter) before a loop starts.
- Infinite loops caused by a condition that never becomes false.
Trace tables
You'll be asked to complete a trace table showing how variable values change line by line - practise this by hand, it's a guaranteed exam question type.
What does casting mean in programming?
Converting a value from one data type to another, e.g. int('5') converts the string '5' to the integer 5
tap to reveal
Why must input() results often be cast in Python?
Because input() always returns a string, even if the user typed a number, so it needs casting with int() or float() before it can be used in maths
tap to reveal
What is the difference between = and ==?
= assigns a value to a variable; == compares two values and returns True or False
tap to reveal
What index number does the first item in an array/list have?
0 - array and list indexing always starts at 0
tap to reveal
What is the difference between // and % in arithmetic?
// (integer/floor division) gives the whole number result; % (modulus) gives only the remainder
tap to reveal
When does a WHILE loop run its body?
It checks the condition first, so the body may run zero times if the condition starts False
tap to reveal
When does a REPEAT-UNTIL loop run its body?
It checks the condition after running the body, so it always executes at least once
tap to reveal
What is a count-controlled loop and give an example?
A loop where the number of repeats is known in advance, e.g. a FOR loop
tap to reveal
What is a condition-controlled loop and give an example?
A loop that repeats until a condition changes, with the number of repeats unknown in advance, e.g. a WHILE loop
tap to reveal
What Boolean values does the AND operator require to return True?
Both conditions must be True
tap to reveal
What Boolean values does the OR operator require to return True?
At least one of the conditions must be True
tap to reveal
What does the NOT operator do?
It reverses a Boolean value - True becomes False and False becomes True
tap to reveal
What is the difference between a variable and a constant?
A variable's value can change while the program runs; a constant's value stays fixed throughout
tap to reveal
What causes an infinite loop?
A loop condition that never becomes false, so the loop body keeps repeating forever
tap to reveal
What is string concatenation?
Joining two or more strings together, usually using the + operator
tap to reveal