Chhetri AcademyGCSE & A level Paper Builder

6.3Data types and data structures

Edexcel GCSE Computer Science (1CP2) · Problem solving with programming

Practise Data types and data structures. 16 exam-style questions plus unlimited generated ones 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 Data types and data structures (Craig 'n' Dave Edexcel on YouTube) · Practise all of Problem solving with programming

Quick recall

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

The program contains this line of code.
sold = input("Seats sold: ")
State the data type of the value stored in sold.
String
State the data type of the variable age after line 01 has run.
String

Sample questions

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

Question 1Easy4 marks
Look at this program.
01 age = input("Enter your age: ")
02 nextYear = int(age) + 1
03 print("Next year you will be " + str(nextYear))
(a) State the data type of the variable age after line 01 has run.[1]
(b) Give a reason why int() is used in line 02.[1]
(c) The user enters 14. State the output of the program.[1]
(d) State what would happen if str() was removed from line 03.[1]
Show the answer and mark scheme
(a) Answer: String
  • string / str
(b) Answer: input() returns a string, so the value in age must be converted to an integer before 1 can be added to it.
  • the input is a string / text, so it must be converted to an integer before arithmetic / adding 1 can be carried out
(c) Answer: Next year you will be 15
  • Next year you will be 15
(d) Answer: A runtime error (a TypeError) would occur, because a string cannot be joined to an integer with +.
  • a runtime error would occur / the program would crash (because a string and an integer cannot be concatenated with +)
Question 2Medium9 marks
A weather station records the maximum temperature, in °C, for each day of one week.
01 temps = [14, 17, 9, 21, 12, 18, 14]
02 total = 0
03 for t in temps:
04     total = total + t
05 mean = total / len(temps)
06 print(mean)
(a) State the output of the program.[1]
(b) State the value of total after the loop has run three times.[1]
(c) Write Python code, to be added to the end of the program, that counts how many of the temperatures are above the mean and then outputs the count.[4]
(d) State the number of temperatures in the list that are above the mean.[1]
(e) Explain why the temperatures are stored in a list rather than in seven separate variables.[2]
Show the answer and mark scheme
(a) Answer: 15.0
  • 15.0
(b) Answer: 40 (14 + 17 + 9)
  • 40
(c) Answer:
count = 0
for t in temps:
    if t > mean:
        count = count + 1
print(count)
  • sets a counter to 0 before the loop
  • loops through every temperature in the list
  • compares each temperature with mean using >
  • adds 1 to the counter when a temperature is above the mean
  • outputs the count after the loop has finished
(d) Answer: 3 (17, 21 and 18)
  • 3
(e) Answer: All seven values are held under one identifier, so a loop can be used to process them, which makes the code shorter and means it still works if more days are added.
  • a loop can be used to process all the values / the code is shorter
  • only one identifier is needed / the related data is kept together
  • the program can easily be changed to work for more days / the list can be extended
Question 3Hard8 marks
A program stores people's names as strings. Each name is made up of words separated by single spaces, for example "ada byron king".
(a) Write a Python function getInitials(name) that returns a string made up of the first letter of each word in name, in upper case.
For example, getInitials("ada byron king") must return "ABK".[5]
(b) State the value returned by getInitials("tim berners lee").[1]
(c) A different programmer writes this version of the function.
01 def getInitials(name):
02     initials = ""
03     for i in range(len(name)):
04         if name[i] == " ":
05             initials = initials + name[i + 1]
06     print(initials)
Describe two problems with this version of the function.[2]
Show the answer and mark scheme
(a) Answer:
def getInitials(name):
    initials = name[0].upper()
    for i in range(1, len(name)):
        if name[i - 1] == " ":
            initials = initials + name[i].upper()
    return initials
  • a function header with one parameter, e.g. def getInitials(name):
  • includes the first character of the name (index 0)
  • loops through the characters of the name (or through the words, e.g. using split(" "))
  • identifies the first letter of every later word, e.g. the character after a space / word[0]
  • converts the initials to upper case using upper()
  • returns the string of initials (rather than printing it)
(b) Answer: TBL
  • TBL (must be in upper case)
(c) Answer: The first letter of the name is never added, because letters are only added after a space; the initials are not converted to upper case; and the initials are printed instead of being returned.
  • the first letter of the name / the initial of the first word is never added (only letters after a space are added)
  • the letters are not converted to upper case
  • it outputs the initials with print instead of returning them, so the calling code cannot use the value

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