Assignment, Variables, Constants & Sequences
Inputs, Outputs & Type Conversion
Condition controlled Loops
Count Controlled loops
Nested Selection and Iteration
Subroutines 1 - Procedures
Subroutines 2 - Functions
Operators and Operations
Structured Programming
Validation and verification
Records
Good notes will help you organise and process data and information
A Record is a data structure that groups together related data items. These are more complex than arrays, as you can store more than one type of data together under one identifier. For example, with a game, it would be useful to set up a data structure which collects a player's login and their score in one structure. Creating records will vary in different languages. Python uses a data structure called a 'dictionary' that has some features of the record structure.
array
collection of data items
one identifier
group data items together
set of data
data structure
stores
key
value
functions
printed dictionary
mutable
value can be changed
curly brackets{ }
studentMarks
#Student Marks Dictionary #The first line defines a new dictionary: studentMarks = {"Owen":7, "William":9, "Libby":5, "Evie":8} #The following code will return all three records in the dictionary: print(studentMarks) >>> {"Mark":7, "William":9, "Libby":5, "Evie":8} #The following code will return Libbys mark in the dictionary: print(studentMarks["Libby"]) >>> 5
mark
accessed
its key
players
Katie
Patrick
kat10
124
pat00
99
dictionary data structure
:
{} curly brackets
commas
#Players Dictionary #The first line defines a new dictionary: players = {"Katie": {"login":"kat10", "score":124 }, "Patrick": {"login":"pat00", "score":99 }} #The next line adds a new record to the dictionary: players["Tom"] = {"login":"tom13", "score":121} #The following code will return all three records in the dictionary: print(players) >>> {'Katie': {'login': 'kat10', 'score': 124}, 'Patrick': {'login': 'pat00', 'score': 99}, 'Tom': {'login': 'tom13', 'score': 121}} #And this line of code would remove Katie's score: del players["Katie"] print(players) >>> {'Patrick': {'login': 'pat00', 'score': 99}, 'Tom': {'login': 'tom13', 'score': 121}}
Dictionary Methods Table
Basic Dictionary Methods
#Student Marks Dictionary - Example 1: Look up a value studentMarks = {"Owen":7, "William":9, "Libby":5, "Keira":8} name= input("Enter a student name to look up: ") if name in studentMarks: print("mark: ", studentMarks[name]) else: print("Name not found")
#Student Marks Dictionary - Example 2: Add a new key-value pair studentMarks = {"Owen":7, "William":9, "Libby":5, "Keira":8} name= input("Enter a student name to look add: ") if name in studentMarks: print(""Name is already in the marks record"") else: mark = input("Enter mark: ") studentMarks[name] = mark
#Student Marks Dictionary - Example 3: Edit a value studentMarks = {"Owen":7, "William":9, "Libby":5, "Keira":8} name= input("Enter a student name to edit their mark: ") if name in studentMarks: mark = input("Enter mark: ") studentMarks[name] = mark else: print("Name not found")
#Student Marks Dictionary - Example 4: Delete a key-value pair studentMarks = {"Owen":7, "William":9, "Libby":5, "Keira":8} name= input("Enter a student name to delete: ") if name in studentMarks: del studentMarks[name] print("Student Deleted") else: print("Name not found")
Lets look at the learning outcomes and decide which one best describes our current level of understanding :
Tick the one you feel is closest to your level
AQA Computer Science Tutor
Python Syntax