← VCE Software Development U3O1

Creating an array of a set size

Creates a one-dimensional array (list) of 10 elements that all start with the value 0. Change the number to set the size, or use '' for strings.

Understanding Creating an array of a set size in VCE Software Development U3O1

What it does: The constant SIZE holds the array length, so changing it once updates the array size everywhere it is used. After the array is created, an element is filled by using its index in square brackets. Index 2 is the third element because indexes start at 0. [0] is the starting value and * 10 is the size. Swapping them gives a list of zero elements. '' is an empty string, so each of the 5 elements starts as an empty string, not the number 0. Storing the size in a constant such as SIZE means you only change it in one place. size() is not a Python function for this.

Common mistakes: x is not a Python operator, so this is a syntax error. Use * to repeat the element: scores = [0] * 10. Repeating an empty list still gives an empty list with 0 elements. Put an empty string inside the brackets: names = [''] * SIZE.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 72–96) and word search (Modules 72–113).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which line creates an array of 10 elements that all start at 0?
scores = [0] * 10scores = [10] * 0
Matches
scores = [0] + 10
↓
Uses + instead of *. A list cannot be added to a number, so this causes an error. It should be [0] * 10 to repeat the 0 ten times.
Applying
Meanings
Term
scores = [0] * 10
Meaning
Creates a one-dimensional array (list) of 10 elements that all start with the value 0. Change the number to set the size, or use '' for strings.
Practice
SIZE = 5
Testing
Gaps
scores = [0] 10
Check Answer
Spots
1scores = [0] x 10
2scores[0] = 85

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Jellyfish' badge — Flow Controller, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which line creates an array of 10 elements that all start at 0?
A. scores = [0] * 10 ✓
B. scores = [10] * 0
[0] is the starting value and * 10 is the size. Swapping them gives a list of zero elements.
2. What does names = [''] * 5 create?
A. An array of 5 zeros
B. An array of 5 empty strings ✓
'' is an empty string, so each of the 5 elements starts as an empty string, not the number 0.
3. How many elements does marks = [0] * 30 have?
A. 1
B. 30 ✓
The number after * sets the size of the array, so there are 30 elements, each set to 0.
4. Which version uses a constant for the array size?
A. SIZE = 8 scores = [0] * SIZE ✓
B. scores = [0] * size()
Storing the size in a constant such as SIZE means you only change it in one place. size() is not a Python function for this.
5. After scores = [0] * 5, what does scores[2] = 17 do?
A. Fills the third element with 17 and leaves the others at 0 ✓
B. Adds 17 to the end and makes the array 6 elements long
Assigning by index replaces the value in that position. It does not change the size. Index 2 is the third element because indexing starts at 0.

Match the Pairs

scores = [0] * 10 → Creates an array of 10 elements, all starting at 0
names = [''] * 5 → Creates an array of 5 empty strings ready to be filled
Use a constant for the size so the array length can be changed in one place → SIZE = 10 scores = [0] * SIZE
Fill an element of a set-size array by its index → scores[2] = 85
scores = [0] + 10 → Uses + instead of *. A list cannot be added to a number, so this causes an error. It should be [0] * 10 to repeat the 0 ten times.
scores = [0 * 10] → The * is inside the brackets, so it makes a list with one element (0 * 10 = 0), not 10 elements. It should be [0] * 10.

Key Term

scores = [0] * 10
Creates a one-dimensional array (list) of 10 elements that all start with the value 0. Change the number to set the size, or use '' for strings.

Fill in the Blanks

1. scores = [0] * 10
Hint: Type the operator that repeats the list item to fill the array.
2. # Array for 5 student names names = [''] * 5
Hint: Type the number of elements that the comment says the array needs.
3. SIZE = 8 marks = [0] * SIZE
Hint: Type the constant name that sets the number of elements.
4. SIZE = 5 scores = [0] * SIZE scores[0] = 75
Hint: Type the index of the first element in the array.
5. scores = [0] * 10 for i in range(len(scores)): scores[i] = i * 5
Hint: Type the function that returns how many elements the array has.

Spot the Error

Question 1
A scores = [0] x 10
B scores[0] = 85
C scores[1] = 92
D print(len(scores))
Line A — x is not a Python operator, so this is a syntax error. Use * to repeat the element: scores = [0] * 10.
Question 2
A SIZE = 5
B names = [] * SIZE
C names[0] = 'Ava'
D print(names)
Line B — Repeating an empty list still gives an empty list with 0 elements. Put an empty string inside the brackets: names = [''] * SIZE.
Question 3
A SIZE = 8
B marks = [0] + SIZE
C for i in range(SIZE):
D marks[i] = i * 10
Line B — You cannot add an integer to a list, so this causes a TypeError. Use * to repeat the starting value: marks = [0] * SIZE.
Question 4
A temps = [0.0] * 7.0
B temps[6] = 31.5
C print(temps)
Line A — The array size must be a whole number. Multiplying a list by a float causes a TypeError. Use the integer 7.
Question 5
A SIZE = 5
B scores = [0] * SIZE
C scores[5] = 90
D print(scores)
Line C — An array of 5 elements has indexes 0 to 4. Index 5 is out of range and causes an IndexError. Use scores[4] = 90 for the last element.

Student with a class code? Join your class →