Functions – Parameters

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

Functions – Parameters

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is a parameter?
A The function name
B A variable in the function definition
2. What is an argument?
A The actual value passed to a function
B The function name
3. def greet(name):\n print('Hi ' + name)\ngreet('Bob')\nWhat prints?
A Hi Bob
B Hi name
4. def add(a, b):\n print(a + b)\nadd(3, 5)\nWhat prints?
A 35
B 8
5. Can a function have multiple parameters?
A Yes separated by commas
B No only one

Match the Pairs

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

Left columnRight column
1def add(a, b): return a + b add(3) AError: Too many arguments
2def greet(name): print('Hi ' + name) greet('Al', 'Bob') BError: Missing argument for b
3def greet(name): print('Hi ' + name) greet('Alice') COutput: 8
4def add(a, b): return a + b DValid: One parameter, one arg
5def square(n): return n * n print(square(4)) EOutput: 16
6def add(a, b): return a + b print(add(3, 5)) FOk: Two parameters

Definitions

Parameter

Fill in the Blanks

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

1.
def greet(____): print('Hi ' + name) greet('Alice')
2.
def add(a, _): print(a + b) add(3, 5)
3.
def greet(name): print('Hi ' + name) greet(_____)
4.
def double(______): print(number * 2) double(5)
5.
def show(x, y): print(x + y) show(_, 10)

Spot the Error

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

Question 1
A def greet(name)
B msg = 'Hi ' + name
C print(msg)
D print('Goodbye!')
E greet('Alice')
Question 2
A def greet('name'):
B msg = 'Hi ' + name
C print(msg)
D print('Goodbye!')
E greet('Alice')
Question 3
A def add(a b):
B result = a + b
C print('Sum:', result)
D return result
E add(3, 5)
Question 4
A def greet(name):
B print('Hi ' + name)
C
D greet()
Question 5
A def greet(name):
B print('Hi ' + name)
C
D greet('Alice', 'Bob')

Answer Key

Functions – Parameters
Section A: Quick Questions
Q1
B — A variable in the function definition
Q2
A — The actual value passed to a function
Q3
A — Hi Bob
Q4
B — 8
Q5
A — Yes separated by commas
Section B: Match the Pairs
Q1
def add(a, b): return a + b add(3) → Error: Missing argument for b
Q2
def greet(name): print('Hi ' + name) greet('Al', 'Bob') → Error: Too many arguments
Q3
def greet(name): print('Hi ' + name) greet('Alice') → Valid: One parameter, one arg
Q4
def add(a, b): return a + b → Ok: Two parameters
Q5
def square(n): return n * n print(square(4)) → Output: 16
Q6
def add(a, b): return a + b print(add(3, 5)) → Output: 8
Section C: Definitions
Q1
Parameter — A variable name in the function definition that receives data.~~Argument
Section D: Fill in the Blanks
Q1
def greet(name): print('Hi ' + name) greet('Alice')
Q2
def add(a, b): print(a + b) add(3, 5)
Q3
def greet(name): print('Hi ' + name) greet(Alice)
Q4
def double(number): print(number * 2) double(5)
Q5
def show(x, y): print(x + y) show(5, 10)
Section E: Spot the Error
Q1
A — Missing colon after the parameter list
Q2
A — Parameters don't use quotes: name is a variable, not a string
Q3
A — Multiple parameters must be separated by commas
Q4
D — Missing argument: greet expects a name but got nothing
Q5
D — Too many arguments: function takes 1 but got 2