Integer
Whole numbers, positive or negative. No decimal point.
e.g. 42, -7, 0
Real / Float
Numbers with a decimal point.
e.g. 3.14, -0.5
Boolean
Only two values — true or false.
e.g. True, False
Character
A single letter, digit, or symbol.
e.g. 'A', '3', '!'
String
A sequence of characters.
e.g. "Hello", "J277"
Variable vs Constant
Variable: value can change. Constant: fixed throughout the program.
| + - * | Add, Subtract, Multiply |
| / | Divide (real result) |
| DIV | Integer division (floor) |
| MOD | Remainder after division |
| ^ | Power / exponent |
| == | Equal to |
| != | Not equal to |
| < > | Less / Greater than |
| <= >= | Less/Greater or equal |
| AND | Both must be true |
| OR | At least one true |
| NOT | Inverts true/false |
IF score >= 70 THEN grade = "Distinction" ELSEIF score >= 50 THEN grade = "Pass" ELSE grade = "Fail" ENDIF
total = 0 FOR i = 0 TO 9 total = total + scores[i] NEXT i average = total / 10
attempts = 0
WHILE attempts < 3
password = input("Enter:")
attempts = attempts + 1
ENDWHILE
An array stores multiple values of the same type in a single variable. Each value is accessed by its index, starting at 0.
# 1D Array scores = [45, 72, 61, 88, 55] print(scores[0]) # outputs 45 print(scores[3]) # outputs 88 # Loop through array FOR i = 0 TO 4 print(scores[i]) NEXT i
# 2D Array (grid)
grid = [[1,2,3],[4,5,6],[7,8,9]]
print(grid[1][2]) # outputs 6
# grid[row][column]
# Loop through 2D array
FOR row = 0 TO 2
FOR col = 0 TO 2
print(grid[row][col])
NEXT col
NEXT row
SQL (Structured Query Language) is used to retrieve data from a database. At GCSE you need SELECT, FROM, WHERE.
-- Select all students with score above 60 SELECT name, score FROM Students WHERE score > 60 -- Select all fields from a table SELECT * FROM Students WHERE year = 11
Step through the program below. Enter the variable values at each step, then click Check.
total = 0 FOR i = 1 TO 4 total = total + i NEXT i print(total)
| Step | Line | i | total |
|---|
Each snippet has one bug. Click to reveal what's wrong.
1. State the difference between a variable and a constant. [2 marks]
Mark scheme:
2. A program uses an array called scores with 10 elements. Write a pseudocode statement to output the value at index 3. [1 mark]
Mark scheme:
print(scores[3])
Accept any pseudocode equivalent that outputs scores[3]. Note: index 3 is the 4th element (0-indexed).
3. The pseudocode below is intended to add up all values in an array. Identify the error and write the corrected line. [2 marks]
total = 0 FOR i = 0 TO 4 total = total + scores NEXT i
Mark scheme:
4. Write a SQL statement to display the name and year group of all students in year 11 from a table called Students. [2 marks]
Mark scheme:
SELECT name, year FROM Students WHERE year = 11
Award 1 mark for correct SELECT/FROM; 1 mark for correct WHERE clause. Accept column names in either order.