Describe, use and exemplify several data types
Describe and use 1D arrays
An array is a data structure.
Arrays let programmers store ‘lists’ of related data in one data structure.
For example, we could use an array to store pupil marks.
Each value in a list is given its own position/index value so it can easily be referenced.
Arrays can be assigned to variables.
Often a program will have to store lots of information at the one time, for example, when a teacher is entering in the names of all their pupils. It is unrealistic to have a separate variable for each of the names (StudentName1, StudentName2….etc).
Arrays allow the programmer to store more than one piece of data within a single data structure.
The element data type can be integers, reals, Booleans, characters or string
strings = [""] * 5
integers = [0] * 5
reals = [0.0] * 5
booleans = [False] * 5
characters = [""] * 5
pupil1Name = "Matthew"
pupil2Name = "Charlie"
pupil3Name = "Emilis"
pupil4Name = "Cameron"
pupil5Name = "Logan"
pupil6Name = "Ruaridh"
pupil7Name = "Jasmine"
pupil8Name = "Ignacy"
pupil9Name = "Findlay"
pupil10Name = "Aimee"
pupil11Name = "Lucas"
pupil12Name = "Billy"
pupil13Name = "AJ"
pupils = [""] * 14
pupils[0] = "Matthew"
pupils[1] = "Charlie"
pupils[2] = "Emilis"
pupils[3] = "Cameron"
pupils[4] = "Logan"
pupils[5] = "Ruaridh"
pupils[6] = "Jasmine"
pupils[7] = "Ignacy"
pupils[8] = "Findlay"
pupils[9] = "Aimee"
pupils[10] = "Lucas"
pupils[11] = "Billy"
pupils[12] = "AJ"
pupils[13] = "Jordan"
This comes up a lot in National 5 assignments!
print("Please insert the number of pupils required.")
numberOfPupilsRequired = int(input())
pupils = [""] * numberOfPupilsRequired
for i in range(0, numberOfPupils):
print("Please insert the name of pupil", i, ".")
pupils[i] = input()
DECLARE playerNames AS ARRAY OF STRING INITIALLY [""]*7
Work through the arrays worksheet
Apply a filter: