GCSE Revision

Variables, constants and operators

Variables and constants

A variable is a named value that can change while a program runs. Assignment stores a value in it. A constant is a named value that should stay the same. In Python, capital letters are a convention for constants, not a rule the interpreter enforces.

const passMark = 50
score = 0
score = score + 1
OUTPUT score

Both programs output 1. Choose names that make each value's purpose clear.

Key terms

Input, output and casting

Input lets a user give a program data; output shows a result. In ERL, use INPUT and OUTPUT. Python's input() gives back text, even when the user types digits. Use int() for a whole number or float() for a number with a decimal part.

INPUT age
INPUT height
OUTPUT age + 1
OUTPUT height

With inputs 15 and 1.6, Python outputs 16 and 1.6. Casting text such as "15" changes it into a number; without casting, age + 1 causes a type error.

Key terms

Arithmetic operators

The same calculations use different symbols in ERL and Python:

OperationERLPythonExample result
RemainderMOD%17 MOD 5 is 2
Integer divisionDIV//17 DIV 5 is 3
Power^**5 ^ 2 is 25

Remainder is what is left after making whole groups. Integer division gives the whole-number quotient. Power multiplies a number by itself: 5 squared is 25. For these positive examples, both languages give the results shown.

Common mistake

In Python, ^ is not the power operator. Use **; ^ means bitwise XOR, which is beyond this specification.

Key terms

Comparison and Boolean operators

A comparison checks two values and gives true or false. Both languages use == for equal to, != for not equal to, and <, >, <= and >= for size comparisons. A single = assigns a value; it does not test equality.

Boolean operators combine or reverse conditions. ERL writes AND, OR and NOT; Python writes and, or and not in lower case. For example, age >= 13 AND age <= 18 is true only when both comparisons are true. Use brackets to make a longer condition clear.

Key terms

Take the quiz