Question 1
1 markA UK postcode, such as "LS6 2QT" or "B1 1AA", always ends with a space followed by a three-character inward code ("2QT" and "1AA" in these examples).
A postcode is stored in the variable postcode. Write an expression that returns its inward code.
Model answer
postcode.right(3)
Explanation
The inward code is always the last three characters, whatever the length of the postcode, so right(3) returns it directly. Using substring with a fixed start position would fail because postcodes are 6, 7 or 8 characters long. The same idea in Python is postcode[-3:].
Mark scheme
-
1 mark
postcode.right(3)
Accept postcode.substring(postcode.length - 3, 3), or Python postcode[-3:] or postcode[len(postcode) - 3:]. Do not accept a fixed start such as postcode.substring(4, 3), which only works for postcodes of one particular length.