One-dimensional arrays

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

One-dimensional arrays

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which statement describes a one-dimensional array?
A A named, ordered collection of elements of the same data type
B A single variable that holds exactly one value
2. In Python, scores = [70, 85, 92]. Which expression gives the first element?
A scores[0]
B scores[1]
3. An array in VCAA-style pseudocode starts at index 1. What is the index of the third element?
A 2
B 3
4. Which array follows the rule that every element has the same data type?
A [12, 7, 19, 4]
B [12, "seven", 19.5, True]
5. names = ["Ava", "Liam", "Mia"] has 3 elements. Which index causes an index out of range error?
A names[2]
B names[3]

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1scores = [72, 85, 90, 64] AIndex 4 is out of range. With zero-based indexing the valid indexes are 0 to 3, so the last element is scores[3].
2scores[2] BThe loop starts at 0 but the array is 1-based. The loop should run from 1 to 5 so every element is reached and no invalid index is used.
3Every element in a one-dimensional array should have the same data type Cscores.append(78)
4A growing list can add an element, while a fixed-size array keeps the same number of elements DReaches the third element of the array, 90, using index 2 (zero-based)
5scores = [72, 85, 90, 64]\nprint(scores[4]) Enames = ["Ava", "Liam", "Mia"]
6FOR i FROM 0 TO 5 PRINT scores[i] (array has 5 elements, 1-based) FCreates a one-dimensional array (list) of four integers named scores

Definitions

one-dimensional array

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
scores = [85, 92, 78, 64] print(scores[_])
2.
scores = [85, 92, 78, 64] print(scores[_])
3.
scores = [85, 92, 78, 64] count = ___(scores)
4.
scores = [85, 92, 78, 64] scores.______(70)
5.
scores = [85, 92, 78, 64] scores[_] = 99

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A scores = [72, 85, 90, 64]
B first = scores[1]
C last = scores[3]
D print(first, last)
Question 2
A names = ["Ava", "Liam", "Mia"
B print(names[0])
C print(len(names))
Question 3
A marks = [50, 60, 70]
B total = 0
C for m in marks:
D total = total + 1
E print(total)
Question 4
A temps ← [18, 21, 19, 25, 23]
B FOR i ← 1 TO 6
C PRINT temps[i]
D END FOR
Question 5
A items = [4, 8, 15, 16]
B for i in range(len(items)):
C print(items[i + 1])

Answer Key

One-dimensional arrays
Section A: Quick Questions
Q1
A — A named, ordered collection of elements of the same data type
Q2
A — scores[0]
Q3
B — 3
Q4
A — [12, 7, 19, 4]
Q5
B — names[3]
Section B: Match the Pairs
Q1
scores = [72, 85, 90, 64] → Creates a one-dimensional array (list) of four integers named scores
Q2
scores[2] → Reaches the third element of the array, 90, using index 2 (zero-based)
Q3
Every element in a one-dimensional array should have the same data type → names = ["Ava", "Liam", "Mia"]
Q4
A growing list can add an element, while a fixed-size array keeps the same number of elements → scores.append(78)
Q5
scores = [72, 85, 90, 64]\nprint(scores[4]) → Index 4 is out of range. With zero-based indexing the valid indexes are 0 to 3, so the last element is scores[3].
Q6
FOR i FROM 0 TO 5 PRINT scores[i] (array has 5 elements, 1-based) → The loop starts at 0 but the array is 1-based. The loop should run from 1 to 5 so every element is reached and no invalid index is used.
Section C: Definitions
Q1
one-dimensional array — A named, ordered collection of elements of the same data type. Each element is reached by its index, its position number (0-based in Python, often 1-based in pseudocode).
Section D: Fill in the Blanks
Q1
scores = [85, 92, 78, 64] print(scores[0])
Q2
scores = [85, 92, 78, 64] print(scores[3])
Q3
scores = [85, 92, 78, 64] count = len(scores)
Q4
scores = [85, 92, 78, 64] scores.append(70)
Q5
scores = [85, 92, 78, 64] scores[2] = 99
Section E: Spot the Error
Q1
B — Python arrays (lists) are zero-based, so the first element is at index 0. scores[1] is the second element. It should be first = scores[0].
Q2
A — The list is missing its closing square bracket. It should be names = ["Ava", "Liam", "Mia"].
Q3
D — This adds 1 each time instead of adding each element's value. It should be total = total + m.
Q4
B — The array has 5 elements, indexed 1 to 5 in this 1-based pseudocode. Going to 6 is out of range. It should be FOR i ← 1 TO 5.
Q5
C — items[i + 1] skips the first element and goes out of range on the last loop. It should be print(items[i]).