Array Notes
Array Notes
What is an array?
Example in Python
# Output:
#1
# 10
#3
#4
#5
DECLARE NamesAndNumbers :
ARRAY[1:3, 1:2] OF STRING
Declare a 2D array called players with name and score assigned for 4
people (Alice, Bob, Charlie & Daisy)
players[2,1] ← "Bob" ]
players[2,2] ← "30"
players[3,1] ← "Charlie"
players[3,2] ← "22"
players[4,1] ← "Daisy"
players[4,2] ← "28"
Example in Python
Initialising a 2D array with 3 rows and 3 columns, with the specified values
Some questions can be X,Y and others can be Y, X. Always refer to the example
before giving your answer!
Worked Example
A parent records the length of time being spent watching TV by 4 children
Data for one week (Monday to Friday) is stored in a 2D array with the identifier
minsWatched.
Write a line of code to output the number of minutes that Harry watched TV on
Friday [1]
Write a line of code to output the number of minutes that Quinn watched TV on
Wednesday [1]
Answers
• print(minsWatched[1][1] OR print(minsWatched[1,1]
• print(minsWatched[4][2] OR print(minsWatched[4,2]
• print(minsWatched[2][0] OR print(minsWatched[2,0]