define: defining a function

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

define: defining a function

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Does define start a function definition?
A True
B False
2. Are parameters listed inside brackets after the function name?
A True
B False
3. Should a function definition close with end function?
A No
B Yes
4. Is DEFINE written in uppercase in VCAA pseudocode?
A True
B False
5. Can multiple parameters be separated by commas inside the brackets?
A True
B False

Match the Pairs

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

Left columnRight column
1define addNumbers(a, b) AThe keyword should be written in lowercase as define, not DEFINE
2end function BCloses a function definition
3A keyword that starts a function's definition and names it CStarts a function named addNumbers with two parameters
4Values listed in brackets after the function name that the function accepts DThe closing keywords should be written as end function, not func end
5DEFINE greetUser(name) DISPLAY "Hello " + name end function E(a, b)
6define subtract(a, b) result ← a - b DISPLAY result func end Fdefine

Definitions

define

Fill in the Blanks

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

1.
______ addNumbers(a, b)
2.
define addNumbers(a, b) result ← a + b DISPLAY result ___ function
3.
define greetUser(name) DISPLAY "Hello " + name end ________
4.
define multiply(x, y) ______ ← x * y DISPLAY result end function
5.
define square(___) DISPLAY num * num end function

Spot the Error

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

Question 1
A define addNumbers(a, b)
B result ← a + b
C DISPLAY result
D end func
Question 2
A DEFINE greetUser(name)
B DISPLAY "Hello " + name
C end function
Question 3
A define multiply(x, y)
B result = x * y
C DISPLAY result
D end function
Question 4
A define square(num)
B PRINT num * num
C end function
Question 5
A define subtract(a, b)
B result ← a - b
C DISPLAY result
D func end

Answer Key

define: defining a function
Section A: Quick Questions
Q1
A — True
Q2
A — True
Q3
B — Yes
Q4
B — False
Q5
A — True
Section B: Match the Pairs
Q1
define addNumbers(a, b) → Starts a function named addNumbers with two parameters
Q2
end function → Closes a function definition
Q3
A keyword that starts a function's definition and names it → define
Q4
Values listed in brackets after the function name that the function accepts → (a, b)
Q5
DEFINE greetUser(name) DISPLAY "Hello " + name end function → The keyword should be written in lowercase as define, not DEFINE
Q6
define subtract(a, b) result ← a - b DISPLAY result func end → The closing keywords should be written as end function, not func end
Section C: Definitions
Q1
define — A keyword that starts a function definition, naming the function and listing the parameters it accepts
Section D: Fill in the Blanks
Q1
define addNumbers(a, b)
Q2
define addNumbers(a, b) result ← a + b DISPLAY result end function
Q3
define greetUser(name) DISPLAY "Hello " + name end function
Q4
define multiply(x, y) result ← x * y DISPLAY result end function
Q5
define square(num) DISPLAY num * num end function
Section E: Spot the Error
Q1
D — A function definition must close with end function, not end func.
Q2
A — The keyword should be written in lowercase as define, not DEFINE.
Q3
B — Assignment in pseudocode uses ←, not =.
Q4
B — VCAA pseudocode uses DISPLAY to output a value, not PRINT.
Q5
D — The closing keywords must be written as end function, not func end.