← IGCSE Computer Science Paper 2

Pseudocode array to Python list

A pseudocode array starting at index 1 becomes a Python list starting at 0, so element Scores[i] is written scores[i - 1] in Python.

Understanding Pseudocode array to Python list in IGCSE Computer Science Paper 2

What it does: Scores[1] in pseudocode is the first element, which is scores[0] in Python. range(5) gives 0, 1, 2, 3, 4, which are the five valid Python indices for a list of 5 elements. Python lists start at index 0, so pseudocode index 1 becomes Python index 0. range() stops before its end value, so range(1, 6) gives 1 to 5. Then use scores[i - 1] inside the loop. Indexes run from 0 to 4. Index 5 would cause an IndexError. It matches pseudocode Scores[5]. A pseudocode array with bounds 1 to 5 holds 5 values, so the Python list is created with 5 items using [0] * 5.

Common mistakes: Pseudocode index i starts at 1, but Python lists start at 0, so the element is scores[i - 1]. Using scores[i] gives an IndexError when i is 5. Marks[1] is the first element in pseudocode, which is index 0 in Python. marks[1] is the second element. It should be marks[0].

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 216–231) and word search (Modules 188–231).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A pseudocode array is declared with DECLARE Scores : ARRAY[1:5] OF INTEGER. Which Python line creates a matching list?
scores = [0] * 5scores = [0] * 4
Matches
scores = [0] * 5 scores[5] = 90
↓
A list of 5 elements has indices 0 to 4, so scores[5] is out of range and causes an IndexError. The last element is scores[4].
Applying
Meanings
Term
scores[i - 1]
Meaning
A pseudocode array starting at index 1 becomes a Python list starting at 0, so element Scores[i] is written scores[i - 1] in Python.
Practice
scores = [0] * 5
Testing
Gaps
scores = [0] *
Check Answer
Spots
2for i in range(1, 6):
3 scores[i] = i * 10

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

The 'Tree Frog' badge — Leap of Logic, 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. A pseudocode array is declared with DECLARE Scores : ARRAY[1:5] OF INTEGER. Which Python line creates a matching list?
A. scores = [0] * 4
B. scores = [0] * 5 ✓
ARRAY[1:5] holds 5 elements, so the list needs 5 items. [0] * 5 makes a list of five zeros.
2. In pseudocode, the first element of an array with lower bound 1 is Scores[1]. What is the same element in Python?
A. scores[0] ✓
B. scores[1]
Python lists start at index 0, so pseudocode index 1 becomes Python index 0.
3. Which Python statement matches the pseudocode Scores[3] ← 70 (array lower bound 1)?
A. scores[2] = 70 ✓
B. scores[3] = 70
Subtract 1 from the pseudocode index: 3 - 1 = 2. Python also uses = for assignment, not ←.
4. Pseudocode uses Scores[i] inside a loop. How is this written in Python so it works the same way?
A. scores[i + 1]
B. scores[i - 1] ✓
The Python index is always one less than the 1-based pseudocode index, so use i - 1.
5. The pseudocode loop is FOR i ← 1 TO 5. Which Python loop keeps the same i values and reaches every element?
A. for i in range(1, 6): ✓
B. for i in range(1, 5):
range() stops before its end value, so range(1, 6) gives 1 to 5. Then use scores[i - 1] inside the loop.

Match the Pairs

scores = [0] * 5 → Creates a Python list of 5 elements, all set to 0, to replace the pseudocode array Scores[1:5]
scores[i - 1] → Python's way of writing the pseudocode element Scores[i] when the array starts at index 1
Pseudocode index 1 is the first element, but the first element of a Python list is at index 0 → scores[0]
A FOR loop from 1 to 5 over a pseudocode array becomes a Python loop over the indices 0 to 4 → for i in range(5):
scores = [0] * 5 scores[5] = 90 → A list of 5 elements has indices 0 to 4, so scores[5] is out of range and causes an IndexError. The last element is scores[4].
for i in range(1, 6): total = total + scores[i] → The pseudocode bounds 1 to 5 were copied directly, so scores[i] skips the first element and scores[5] is out of range on the last pass.

Key Term

scores[i - 1]
A pseudocode array starting at index 1 becomes a Python list starting at 0, so element Scores[i] is written scores[i - 1] in Python.

Fill in the Blanks

1. # ARRAY[1:10] OF INTEGER scores = [0] * 10
Hint: Type the number of elements the list needs, the same as the size of the pseudocode array.
2. # Scores[1] in pseudocode print(scores[0])
Hint: Type the Python index of the first element in a list.
3. for i in range(1, 6): print(scores[i - 1])
Hint: Type the number subtracted from i to turn a 1-based index into a 0-based index.
4. # FOR i = 1 TO 5 for i in range(1, 6): print(scores[i - 1])
Hint: Type the stop value for range(), which is one more than the last index in the pseudocode loop.
5. for i in range(1, 4): total = total + scores[i - 1]
Hint: Type the operator that converts the pseudocode index into the Python index.

Spot the Error

Question 1
A scores = [0] * 5
B for i in range(1, 6):
C scores[i] = i * 10
D print(scores)
Line C — Pseudocode index i starts at 1, but Python lists start at 0, so the element is scores[i - 1]. Using scores[i] gives an IndexError when i is 5.
Question 2
A marks = [50, 60, 70, 80]
B first = marks[1]
C last = marks[3]
D print(first, last)
Line B — Marks[1] is the first element in pseudocode, which is index 0 in Python. marks[1] is the second element. It should be marks[0].
Question 3
A nums = [4, 8, 2, 6, 1, 9]
B for i in range(1, 6):
C print(nums[i - 1])
Line B — FOR i <- 1 TO 6 runs six times, but range(1, 6) stops at 5 and misses the last element. It should be range(1, 7).
Question 4
A prices = [0] * 3
B prices[1] = 2.5
C prices[1] = 3.0
D prices[2] = 1.2
E print(prices)
Line B — Prices[1] in pseudocode is the first element, so in Python it is prices[0]. Writing prices[1] puts the value in the wrong place and it gets overwritten on the next line.
Question 5
A scores = [0] * 4
B for i in range(1, 5):
C x = int(input())
D scores[i + 1] = x
E print(scores)
Line D — To convert a 1-based pseudocode index to a 0-based Python index you subtract 1, not add 1. It should be scores[i - 1].

Student with a class code? Join your class →