Storing test cases as a list of tuples
A list of (input, expected) tuples. Each tuple is one test case, so a loop can run many tests stored in one variable. Add a new tuple to add a new test.
Understanding Storing test cases as a list of tuples in ACARA Digital Technologies Years 9–10
What it does: The tuple (4, 16) means input 4 should give expected output 16. One tuple is one test case. append() takes one item. The double brackets mean the tuple (10, 100) is that one item. Without them, Python raises a TypeError. Keeping all the tests in one list means a for loop can go through them one at a time. tests is a list, not a function, so it has no brackets after it. Each tuple unpacks into two names. Tuples in a list must be separated by a comma. Leaving it out is a SyntaxError.
Common mistakes: The tuples in the list are not separated by a comma, so Python raises a SyntaxError. It should be tests = [(5, 25), (0, 0)]. The list is missing its closing square bracket, so Python raises a SyntaxError. It should end with )] like tests = [(5, 25), (0, 0)].
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 591–622) and word search (Modules 536–622).
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
tests = [(5, 25), (0, 0)]Fill in the Blanks
Spot the Error
Student with a class code? Join your class →