Runtime error: index out of range
A runtime error raised when code uses an index that is not in the list, such as items[5] in a 5-item list. The last valid index is len(items) - 1.
Understanding Runtime error: index out of range in VCE Software Development U3O1
What it does: The check makes sure i is between 0 and len(items) - 1 before the list is accessed, so no IndexError is raised. An empty list has no valid indexes at all, so even index 0 is out of range. The first index is 0, so the last valid index is one less than the length. Using len(items) as an index goes past the end and causes an IndexError. A list with 5 items has indexes 0 to 4, so len(items) is 5 and is one past the end.
Common mistakes: The list has 5 items, so the last valid index is 4 (len(scores) - 1). Using last + 1 gives index 5, which raises an IndexError. It should be print(scores[last]). This is an off-by-one error. range(count + 1) makes i reach 3, but the valid indexes are 0 to 2, so names[3] raises an IndexError. It should be range(count).
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 156–166) and word search (Modules 142–166).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
IndexErrorFill in the Blanks
Spot the Error
Student with a class code? Join your class →