3_2_6 Data Structures

You should be able to:

  • Understand the concept of data structures.
  • Use arrays (or equivalent) in the design of solutions to simple problems.
  • Use records (or equivalent) in the design of solutions to simple problems.

REVISE:

Data Structures and Arrays

Re-visit 8_1_6

Records

A simple way to create a record using Python is to use a 2-dimensional (2d) array. You might have used a 2d array if you have ever made a noughts and crosses game:

ox = [
        ["x", "x", "x"],
        ["o", "o", "o"],
        ["x", "o", "x"],
      ]

for item in ox:
    print (item)

This code just prints a simple board with the noughts and crosses already entered.

A record stores data on one person, object or theme. A record could be created to store the game scores of different players.

scores = [
        ["PLAYER", "SCORE"],
        ["DinoFish", 23],
        ["JungleQ", 94],
      ]

for item in scores:
    print (item)

Slightly advanced...

You can create records using arrays and link items together with their index numbers. The code below shows an example of this:

films = []
genres = []
durations = []
filmsToAdd = True
while filmsToAdd: # adds the film details to each array
    film = input("Name the film :")
    films.append(film)
    genre = input("What is the genre :")
    genres.append(genre)
    duration = input("What is the duration :")
    durations.append(duration)
    another=input("Would you like to add another film? Y/N").upper()
    if another =="N":
        filmsToAdd = False

for x in range (0,len(films)): # prints each record in turn
    print ("Film ID: "+str(x))
    print (films[x])
    print (genres[x])
    print (durations[x])

TEST:

  1. Download and print the test paper here: https://drive.google.com/open?id=0B5fLtQ0Xgr2PNFpQQndPRDRUcnc
  2. Try the mock test yourself.
  3. Use the 3.2.6 Walking Talking Mock below to guide you through answering the questions.

Programming Task

Choose a database theme to create from the list below:

  • Computer Games
  • TV Box Sets
  • Books
  • Car Types
  • Members of a gym

Using the "slightly advanced" code above as a starting point, create a database for you chosen theme.

Extra Mile

Can you ensure that the data is also validated? See 9_2_2 for help with this.

SOURCE RECOGNITION - PLEASE NOTE: The examination examples used in these walking talking mocks are samples from AQA from their non-confidential section of the public site. They also contain questions designed by TeachIT for AQA as part of the publicly available lesson materials.