Year 9 · Quiz 2

Functions

10 multiple-choice questions on def, parameters, return, and using functions with grids. Matches Part 3 (and function examples in later parts) of the Year 9 Python tutorial.

Predict output Fill blanks Find errors
Fill in the blank

Question 1

You define a function in Python with the keyword ___.

Choose one answer
Predict the output

Question 2

def greet(name):
    print("Hello,", name)

greet("Aisha")
greet("Ben")
Choose one answer
Parameters

Question 3

In def greet(name):, what is name?

Choose one answer
Predict the output

Question 4

def double(n):
    return n * 2

print(double(7))
print(double(10))
Choose one answer
Return

Question 5

What does return do in a function?

Choose one answer
Find the error

Question 6

What is wrong?

def add(a, b)
    return a + b
Choose one answer
Predict the output

Question 7

def add(a, b):
    return a + b
    print("Done")

print(add(3, 4))
Choose one answer
Predict the output

Question 8

def count_at_least(grid, limit):
    count = 0
    for row in grid:
        for value in row:
            if value >= limit:
                count = count + 1
    return count

print(count_at_least([[4, 7], [1, 5]], 5))
Choose one answer
Fill in the blank

Question 9

To give back a row total from a function, complete:

def row_total(grid, row_index):
    total = 0
    for value in grid[row_index]:
        total = total + value
    ___ total
Choose one answer
Why functions

Question 10

Why write a function like print_grid(grid) instead of copying nested loops everywhere?

Choose one answer

Previous: Quiz 1 · Year 9 Python · All quizzes