You should be able to:
Re-visit 8_1_6
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 = Truewhile 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 = Falsefor 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])Choose a database theme to create from the list below:
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.