Parameters versus arguments

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

Parameters versus arguments

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. In def greet(name):, what is name?
A An argument
B A parameter
2. In the call greet('Ava'), what is 'Ava'?
A An argument
B A parameter
3. Which statement is correct?
A Arguments appear in the definition, parameters appear in the call
B Parameters appear in the definition, arguments appear in the call
4. Given def area(w, h):, which call passes the right number of arguments?
A area(4, 5)
B area(4)
5. Given def sub(a, b): return a - b, what does sub(10, 3) return?
A 7
B -7

Match the Pairs

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

Left columnRight column
1def area(width, height): Aarea(height=3, width=5)
2area(5, 3) BThe positional arguments are in the wrong order, so name receives 16 and age receives 'Zoe'.
3A keyword argument names the parameter it is giving a value to, so the order does not matter Cwidth and height are parameters: names in the definition that will receive values
4The number of arguments in a call must match the number of parameters in the definition (unless defaults are set) DThe function has two parameters but the call gives only one argument, so Python raises a TypeError for the missing argument b.
5def total(a, b): return a + b total(4) Edef greet(name, town): greet('Ava', 'Perth')
6def info(name, age): print(name, age) info(16, 'Zoe') F5 and 3 are arguments: the actual values passed in the call, matched by position

Definitions

parameter

Fill in the Blanks

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

1.
def greet(____): print('Hello, ' + name)
2.
def area(w, h): return w * h print(area(w=4, _=5))
3.
def sub(a, b): return a - b print(sub(__, 4)) # 6
4.
def intro(name, ___): print(name, age) intro('Ava', 16)
5.
def greet(name): print('Hi ' + name) greet(name_'Ava')

Spot the Error

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

Question 1
A def greet(name):
B print('Hi', name)
C greet()
Question 2
A def area(w, h):
B return w * height
C print(area(3, 4))
Question 3
A # show one student
B def show(name mark):
C print(name, mark)
D show('Ava', 90)
Question 4
A def box(w, h):
B return w * h
C print(box(h=2, 5))
Question 5
A def add(2, 3):
B return a + b
C print(add(2, 3))

Answer Key

Parameters versus arguments
Section A: Quick Questions
Q1
B — A parameter
Q2
A — An argument
Q3
B — Parameters appear in the definition, arguments appear in the call
Q4
A — area(4, 5)
Q5
A — 7
Section B: Match the Pairs
Q1
def area(width, height): → width and height are parameters: names in the definition that will receive values
Q2
area(5, 3) → 5 and 3 are arguments: the actual values passed in the call, matched by position
Q3
A keyword argument names the parameter it is giving a value to, so the order does not matter → area(height=3, width=5)
Q4
The number of arguments in a call must match the number of parameters in the definition (unless defaults are set) → def greet(name, town): greet('Ava', 'Perth')
Q5
def total(a, b): return a + b total(4) → The function has two parameters but the call gives only one argument, so Python raises a TypeError for the missing argument b.
Q6
def info(name, age): print(name, age) info(16, 'Zoe') → The positional arguments are in the wrong order, so name receives 16 and age receives 'Zoe'.
Section C: Definitions
Q1
parameter — The name in a function definition that receives a value, like name in def greet(name). The value passed in the call, like greet('Ava'), is the argument.
Section D: Fill in the Blanks
Q1
def greet(name): print('Hello, ' + name)
Q2
def area(w, h): return w * h print(area(w=4, h=5))
Q3
def sub(a, b): return a - b print(sub(10, 4)) # 6
Q4
def intro(name, age): print(name, age) intro('Ava', 16)
Q5
def greet(name): print('Hi ' + name) greet(name='Ava')
Section E: Spot the Error
Q1
C — The function has one parameter, name, so the call must pass one argument. greet() passes none and causes a TypeError. It should be greet('Ava').
Q2
B — The parameters are w and h. The name height does not exist inside the function, so Python raises a NameError. It should be return w * h.
Q3
B — Parameters in a function definition must be separated by commas. It should be def show(name, mark):.
Q4
C — A positional argument cannot come after a keyword argument, which is a SyntaxError. Either name both, as in box(h=2, w=5), or use positions only, as in box(5, 2).
Q5
A — A definition lists parameter names, not values. Values such as 2 and 3 are arguments and belong in the call. It should be def add(a, b):.