Chhetri AcademyGCSE & A level Paper Builder

1.2.2Variables, constants and data structures (strings, arrays and records)

Edexcel GCSE Computer Science (1CP2) · Computational thinking › Algorithms

Practise Variables, constants and data structures (strings, arrays and records). 12 exam-style questions on this subtopic, at up to four difficulty levels, with full mark schemes and a progress tracker. Free, no account needed.

Build a paper on this topic

▶ Watch videos on Variables, constants and data structures (strings, arrays and records) (Craig 'n' Dave Edexcel on YouTube) · Practise all of Algorithms

Quick recall

Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.

Define the term 'variable'.
A named memory location holding a value that can change while the program runs.
This program works out the total price of an item including VAT.
01 VAT_RATE = 0.2
02 price = float(input("Enter the price: "))
03 vat = price * VAT_RATE
04 total = price + vat
05 print("Total:", total)
Identify the constant in the program.
VAT_RATE
A music app stores the songs in a playlist in a one-dimensional array. In Python, the array is a list. The first item has index 0.
playlist = ["Sunrise", "Echoes", "Paper Planes",
            "Tidal", "Neon Lights"]
State the output of print(playlist[2]).
Paper Planes
An online shop uses this program to work out the total cost of an order. By convention, the identifiers of constants are written in capital letters.
01 VAT_RATE = 0.2
02 DELIVERY = 4.99
03 cost = float(input("Cost of goods: "))
04 vat = cost * VAT_RATE
05 total = cost + vat + DELIVERY
06 print("Total to pay:", round(total, 2))
Identify one constant used in the program.
VAT_RATE or DELIVERY

Sample questions

Written for this site in the style of Edexcel exam questions. They are not taken from real past papers.

Question 1Easy3 marks
(a) Define the term 'variable'.[1]
(b) State one difference between a variable and a constant.[1]
(c) Identify the data structure that holds a number of items of the same data type, each accessed using an index.[1]
  • Array
  • Record
  • Constant
  • Boolean
Show the answer and mark scheme
(a) Answer: A named memory location holding a value that can change while the program runs.
  • a named location in memory that stores a value, which can change while the program is running
(b) Answer: A constant's value stays the same while the program runs; a variable's value can change.
  • the value of a constant cannot change while the program is running, whereas the value of a variable can change
(c) Answer: Array
Question 2Medium4 marks
This program works out the total price of an item including VAT.
01 VAT_RATE = 0.2
02 price = float(input("Enter the price: "))
03 vat = price * VAT_RATE
04 total = price + vat
05 print("Total:", total)
(a) Identify the constant in the program.[1]
(b) Identify one variable in the program.[1]
(c) Explain one benefit of using a constant for the VAT rate instead of writing 0.2 wherever it is needed.[2]
Show the answer and mark scheme
(a) Answer: VAT_RATE
  • VAT_RATE
(b) Answer: price
  • price / vat / total
(c) Answer: If the rate changes, only line 01 needs editing, so no occurrence of 0.2 can be missed (and the name makes the code clearer).
  • if the VAT rate changes, it only has to be changed in one place (line 01) / the meaningful name shows what the value is
  • so every part of the program uses the new value and none is missed / so the code is easier to read and maintain
Question 3Hard6 marks
A sports club stores details of its 200 members: each member's name, membership number, date of joining and whether they have paid this year's fee.
(a) Describe how the club could use records and an array to store these details.[4]
(b) Explain why storing the details in four separate arrays, one for each item, could cause problems.[2]
Show the answer and mark scheme
(a) Answer: One record per member with a field for each detail (string, integer, date, Boolean), and an array of 200 of these records that a loop can process.
  • each member's details are stored in one record
  • with one field for each item: name (string), membership number (integer), date of joining (string / date) and paid (Boolean)
  • the 200 records are stored in an array, one element for each member
  • so a loop can go through the array to process every member, e.g. to list the members who have not paid
  • each field is accessed by its name (or its position in the record), so the details of one member stay together
(b) Answer: A member's details are linked only by their index, so changing or sorting one array but not the others mixes up different members' details.
  • the details of one member are spread across four arrays and are only linked by being at the same index
  • if one array is sorted, or has an item added or removed, without the others being changed in the same way, the details become mismatched (they belong to the wrong member)

Related subtopics

Stuck? Get 1-to-1 help. Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.

Book a free trial