Check your understanding of the previous reading: recognising function and method calls, and predicting the results of calling functions and methods with arguments.

Question 1

Mark all of the following that are valid function or method calls. Do not worry about whether a variable actually exists — only determine whether 1) this is a function or method call, and 2) the syntax is valid.

Select every one that qualifies, then check.

  • Correct. A value, then a dot, then a name, then parentheses — that is a valid method call.
  • Not quite. A line cannot start with a bare dot — there is no value in front of it to call the method on, so this is not valid syntax at all.
  • Not quite. Without parentheses this is just a name being referenced, not called.
  • Correct. A name followed by parentheses is a valid function call, here with three arguments.
  • Not quite. This is an assignment statement — no parentheses, so no call is happening.
  • Correct. A name followed by parentheses, this time with zero arguments — still a valid function call.
  • Correct, by the question's own rule: a value followed by parentheses is call syntax, and the syntax here is valid. (It would actually crash if you ran it, since a string is not something you can call — but the question asks you to ignore that and judge the syntax.)
  • Correct. A string literal, a dot, a method name, and parentheses — a valid method call.

Question 2

Identify whether each of the following is a method call or a function call.
list.append()
print()
function.call()
method()
"function".method()

Question 3

How would you call a function named openDoor? Assume it takes no arguments.

Show worked solution

A function call needs the function's name immediately followed by parentheses. Since openDoor takes no arguments, the parentheses stay empty: openDoor().

Question 4

The function makeCat below returns the string "Cat". What value will the variable x hold after this line runs?

x = makeCat() + makeCat() + makeCat()

Show worked solution

Each call to makeCat() is replaced by the string "Cat". The + operator on strings concatenates them, so "Cat" + "Cat" + "Cat" evaluates to "CatCatCat".

Question 5

The function add5 below returns the number 5 added to its argument. What value will the variable x hold after this line runs?

x = add5(10) * add5(2)

Show worked solution

add5(10) returns 15, and add5(2) returns 7. Multiplying them: 15 * 7 = 105.

Question 6

True or False: Functions are reusable chunks of code that have inputs and outputs.

Select one answer, then check.

  • Correct. Functions take arguments as input, process them, and can return a value as output — and once written, they can be reused wherever they're needed.
  • Not quite. This is exactly what a function is: a reusable chunk of code with inputs (arguments) and outputs (a return value).