← ACARA Digital Technologies Years 9–10

Passing a list into a function

A function header with a list parameter. Pass a list when you call it, like total_of([5, 8, 9]), and the function can loop over or read its items.

Understanding Passing a list into a function in ACARA Digital Technologies Years 9–10

What it does: Because scores is a list parameter, a for loop can visit each item and add it to the running total. Each call passes a different list, so the function works on that list's items each time. Lists are indexed with square brackets. Round brackets would try to call scores like a function. The name in the brackets of the def line is the parameter, and it will hold whatever list the caller passes in.

Common mistakes: A function header must end with a colon. It should be def total_of(scores): so that the indented body belongs to the function. You can't divide a number by a whole list, which causes a TypeError. Divide by the count of items, so it should be return total / count.

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 629–680) and word search (Modules 629–707).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which function header takes a list called scores as a parameter?
def total_of[scores]:def total_of(scores):
Matches
def total_of([5, 8, 9]):
↓
A list value was put in the def line. The header needs a parameter name like scores, and the list is passed when calling the function.
Applying
Meanings
Term
def total_of(scores):
Meaning
A function header with a list parameter. Pass a list when you call it, like total_of([5, 8, 9]), and the function can loop over or read its items.
Practice
def total_of(scores):
Testing
Gaps
def total():
Check Answer
Spots
1def total_of(scores)
2 total = 0

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

The 'Red Panda' badge — Forest Explorer, 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 function header takes a list called scores as a parameter?
A. def total_of[scores]:
B. def total_of(scores): ✓
A function header uses round brackets around its parameter names. The parameter scores then holds whatever list is passed in.
2. Which call correctly passes a list into total_of()?
A. total_of([5, 8, 9]) ✓
B. total_of(5, 8, 9)
Square brackets build one list, and that single list is passed as one argument. total_of(5, 8, 9) gives three arguments, but the function expects one.
3. Inside def total_of(scores):, what does scores hold when we call total_of([4, 6])?
A. Only the number 4
B. The list [4, 6] ✓
The parameter receives the whole list. You can then loop over it or read items with scores[0], scores[1] and so on.
4. Which loop lets a function read every item in its list parameter scores?
A. for score in scores: ✓
B. for score in total_of:
Loop over the parameter name, scores. total_of is the function's name, not the list.
5. Which statement about calling total_of() is true?
A. You can call it with different lists, such as [5, 8] and [10, 20, 30] ✓
B. It only works with the first list it was ever called with
A parameter is a placeholder. Each call can pass a different list, and the function works on whichever list it receives.

Match the Pairs

def total_of(scores): → Defines a function with a parameter called scores that will receive a list
total_of([5, 8, 9]) → Calls the function and passes in a list of three numbers
The function can loop over every item in the list it was given → for s in scores: total += s
The same function can be reused with different lists → total_of(maths) total_of(science)
def total_of([5, 8, 9]): → A list value was put in the def line. The header needs a parameter name like scores, and the list is passed when calling the function.
total_of(scores) # scores was never created → The call uses a list variable that has not been created, so Python raises a NameError.

Key Term

def total_of(scores):
A function header with a list parameter. Pass a list when you call it, like total_of([5, 8, 9]), and the function can loop over or read its items.

Fill in the Blanks

1. def total(scores): result = 0 for s in scores:
Hint: Type the parameter name that will hold the list passed in. The loop below uses it.
2. def total(scores): return sum(scores)
Hint: Type the built-in function that adds up all the items in the list parameter.
3. def total(scores): result = 0 for score in scores:
Hint: Type the keyword that makes the loop go through each item of the list parameter.
4. marks = [70, 85, 90] print(total(marks))
Hint: Type the name of the variable holding the list so it is passed to the function as an argument.
5. def average(scores): return sum(scores) / len(scores)
Hint: Type the built-in function that counts how many items are in the list parameter.

Spot the Error

Question 1
A def total_of(scores)
B total = 0
C for s in scores:
D total += s
E return total
Line A — A function header must end with a colon. It should be def total_of(scores): so that the indented body belongs to the function.
Question 2
A def average(marks):
B total = sum(marks)
C count = len(marks)
D return total / marks
E print(average([70, 80, 90]))
Line D — You can't divide a number by a whole list, which causes a TypeError. Divide by the count of items, so it should be return total / count.
Question 3
A def biggest(nums):
B top = nums[0]
C for n in nums:
D if n > top
E top = n
F return top
Line D — An if statement needs a colon at the end of the line. It should be if n > top: so the indented line below runs when the test is true.
Question 4
A def show_all(names):
B for name in names:
C print(nam)
D show_all(['Ava', 'Liam'])
Line C — The loop variable is called name, not nam. Using nam causes a NameError. It should be print(name).
Question 5
A def count_pass(marks):
B passed = 0
C for m in range(marks):
D if m >= 50:
E passed += 1
F return passed
Line C — range() needs a number, not a list, so this causes a TypeError. To loop over the items in the list parameter, write for m in marks:.

Student with a class code? Join your class →