All exams← All GCSE Computer Science (Edexcel) notes

Programming fundamentals: GCSE Computer Science (Edexcel) revision notes

Revision notes

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.

Key facts

Flashcards

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
Practice questions

Programming fundamentals: 5 practice questions

Q1. In Edexcel pseudocode, which statement correctly declares an integer variable called score and assigns it the value 10?
  • A.  SET score TO 10
  • B.  score := 10 AS INTEGER
  • C.  DECLARE score = INTEGER(10)
  • D.  INT score = 10
Show answer & explanation
✓ Answer: A. SET score TO 10
In Edexcel's pseudocode command set, a value is assigned to a variable using SET <variable> TO <value>, for example SET score TO 10 or SET Counter TO 0. Edexcel does not use '=' for assignment (that is Python/many languages); in Edexcel pseudocode '=' is used only to test equality inside a condition such as IF score = 10. The other options mix in syntax from other languages or invent forms Edexcel pseudocode does not use.
Q2. What is the key difference between a variable and a constant in programming?
  • A.  A variable is used in loops, a constant is used in selection statements
  • B.  A variable can only store numbers, a constant can store any data type
  • C.  A constant must be declared inside a subroutine, a variable must be declared globally
  • D.  A variable's value can change while a program runs, a constant's value stays fixed once set
Show answer & explanation
✓ Answer: D. A variable's value can change while a program runs, a constant's value stays fixed once set
A variable is a named storage location whose value can be changed during program execution, whereas a constant is given a value once (e.g. VAT_RATE = 0.2) that does not change. Neither is restricted to particular data types or particular parts of a program.
Q3. Which of these is the correct data type to store the value True or False?
  • A.  Boolean
  • B.  Integer
  • C.  Real
  • D.  Character
Show answer & explanation
✓ Answer: A. Boolean
Boolean is the data type that holds one of exactly two values, True or False, used for logical conditions. Integer and Real store numbers, and Character stores a single text symbol.
Q4. A program contains the line: age = int(input("Enter your age: ")). What is the purpose of int() here?
  • A.  It casts the text entered by the user into an integer data type
  • B.  It converts the age into a string for display
  • C.  It checks that the age entered is a positive number
  • D.  It rounds the age to the nearest ten
Show answer & explanation
✓ Answer: A. It casts the text entered by the user into an integer data type
input() always returns a string, so int() casts (converts) that string into an integer so it can be used in numeric calculations or comparisons. int() does not validate or round the value, and it converts to a number, not to a string.
Q5. Which sequence of instructions best describes 'selection' in programming?
  • A.  A structure where one of two or more paths is chosen based on a condition, e.g. IF...THEN...ELSE
  • B.  A set of instructions executed one after another in order, with no branching
  • C.  A set of instructions that repeats a fixed number of times
  • D.  A structure that stores multiple values under one variable name
Show answer & explanation
✓ Answer: A. A structure where one of two or more paths is chosen based on a condition, e.g. IF...THEN...ELSE
Selection is a control structure, such as IF...THEN...ELSE or CASE, where the program chooses which instructions to run based on whether a condition is True or False. Repeating instructions is iteration, and simple ordered execution is sequence.
Test yourself
See the GCSE Computer Science (Edexcel) page

More GCSE Computer Science (Edexcel) topics