Calling a function

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Calling a function

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does calling a function require its name followed by brackets containing arguments?
A True
B False
2. Should arguments in a function call be separated by commas?
A False
B True
3. Can the value returned by a function call be stored in a variable?
A True
B False
4. Should a function call with no arguments still include empty brackets?
A False
B True
5. Does a function call need to use square brackets, like myFunc[3, 4]?
A False
B True

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1addNumbers(3, 4) ACalling a function
2total ← addNumbers(3, 4) BStores the value returned by a function call in a variable
3Writing a function's name followed by arguments in brackets CCalling a function requires brackets around its arguments
4Values passed into a function call, matching the parameters it expects DA function call uses round brackets, not square brackets
5total <- addNumbers 3, 4 E(3, 4)
6size ← area[5, 3] FCalls the addNumbers function with two arguments

Definitions

addNumbers(3, 4)

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
total ← __________(3, 4)
2.
total ← addNumbers(_, _)
3.
result ← multiply(6, _)
4.
message ← greet("___")
5.
DISPLAY addNumbers(2, _)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A define addNumbers(a, b)
B return a + b
C end function
D total <- addNumbers 3, 4
Question 2
A total <- addNumbers 3, 4
B define addNumbers(a, b)
C return a + b
D end function
Question 3
A define double(n)
B return n * 2
C end function
D output = double(6)
Question 4
A define computeArea(length, width)
B size <- computeArea 5, 3
C return length * width
D end function
Question 5
A define multiply(x, y)
B answer <- multiply(3 4)
C return x * y
D end function

Answer Key

Calling a function
Section A: Quick Questions
Q1
A — True
Q2
B — True
Q3
A — True
Q4
B — True
Q5
A — False
Section B: Match the Pairs
Q1
addNumbers(3, 4) → Calls the addNumbers function with two arguments
Q2
total ← addNumbers(3, 4) → Stores the value returned by a function call in a variable
Q3
Writing a function's name followed by arguments in brackets → Calling a function
Q4
Values passed into a function call, matching the parameters it expects → (3, 4)
Q5
total <- addNumbers 3, 4 → Calling a function requires brackets around its arguments
Q6
size ← area[5, 3] → A function call uses round brackets, not square brackets
Section C: Definitions
Q1
addNumbers(3, 4) — Calling a function by writing its name followed by arguments in brackets, running its instructions and possibly producing a value
Section D: Fill in the Blanks
Q1
total ← addNumbers(3, 4)
Q2
total ← addNumbers(3, 4)
Q3
result ← multiply(6, 7)
Q4
message ← greet("Sam")
Q5
DISPLAY addNumbers(2, 5)
Section E: Spot the Error
Q1
D — Calling a function requires brackets around the arguments, such as addNumbers(3, 4).
Q2
A — Calling a function requires brackets around the arguments, such as addNumbers(3, 4).
Q3
D — Assignment in pseudocode uses ←, not =.
Q4
B — Calling a function requires brackets around its arguments — it should read computeArea(5, 3).
Q5
B — Arguments in a function call must be separated by a comma, such as multiply(3, 4).