Free Practice Quiz Question List

06. Procedures and Functions Online Quiz Questions

Use this free practice quiz with 20 questions to review 06. Procedures and Functions, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

What normally happens when Python executes a function definition such as def greet(): print("Hello!")?

  1. A

    The function body runs immediately when Python reads the definition.

  2. B

    The function body normally runs when the function is called.

  3. C

    The function body runs only after a value is returned.

  4. D

    The function body runs whenever its name is assigned to a variable.

02
True or false
1 point

True or false: In def greet_person(name): ..., name is a parameter, while in greet_person("Maya"), "Maya" is an argument.

  1. A

    True

  2. B

    False

03
Written response
1 point

What programming term names the variable in a function definition that receives a value supplied by the caller?

04
Fill in the blank
1 point

Complete the statement: If a Python function reaches the end without returning a value, it returns .

05
Choose one
1 point

In the function def square(number): ..., which statement makes the squared value available to the code that called the function?

  1. A

    print(number * number)

  2. B

    result = number * number

  3. C

    return number * number

  4. D

    number = number * number

06
Choose all
1 point

Given def power(base, exponent=2): return base ** exponent, select all correct statements.

  1. A

    power(5) returns 25.

  2. B

    power(5) returns 125.

  3. C

    power(5, 3) returns 125.

  4. D

    power(5, 3) returns 25.

07
True or false
1 point

True or false: If a function executes a return statement, a later statement in that same function body will still execute normally.

  1. A

    True

  2. B

    False

08
Written response
1 point

In the material's abstraction example, what is the exact function name that lets a caller test whether a number is divisible by 2?

09
Fill in the blank
1 point

Complete the statement: A function that modifies the list supplied by its caller produces a .

10
Choose one
1 point

Which statement best describes the variable tax created inside calculate_total(price, tax_rate)?

  1. A

    A variable created inside a function is automatically global.

  2. B

    A variable created inside a function is usually local to that function call.

  3. C

    A local variable can be accessed from any function in the program.

  4. D

    A local variable exists only while the program is being defined.

11
Choose all
1 point

In the decomposition example with weighted_score, letter_grade, and report_result, select all accurate descriptions of the functions' responsibilities.

  1. A

    weighted_score calculates the weighted numerical score.

  2. B

    letter_grade calculates the weighted numerical score.

  3. C

    letter_grade determines the letter category from a score.

  4. D

    report_result coordinates the smaller operations.

12
Open ended
1 point

Explain what happens when this code runs, and why: def double_and_print(number): print(number * 2) followed by result = double_and_print(4).

13
Choose one
1 point

Which design choice best makes a function's dependencies visible and supports testing?

  1. A

    Pass required data as parameters and return results explicitly.

  2. B

    Use global variables so every function can access the same data.

  3. C

    Put all calculations into one large function to avoid communication between functions.

  4. D

    Hide required inputs in unrelated local variables.

14
Choose one
1 point

Consider this Python code: def greet_person(name): print("Hello, " + name + "!"); the function is called with greet_person("Maya"). Which statement correctly identifies the parameter and the argument?

  1. A

    name is the argument and "Maya" is the parameter.

  2. B

    name is the parameter and "Maya" is the argument.

  3. C

    Both name and "Maya" are parameters.

  4. D

    Both name and "Maya" are arguments.

15
Choose one
1 point

What happens when this function is called as result = choose()?

def choose():
return 7
print(9)

  1. A

    The function prints 7 and then returns None.

  2. B

    The function prints both 7 and 9.

  3. C

    The function returns 7 and does not print 9.

  4. D

    The function returns 9 because it is the last expression.

16
Choose one
1 point

In the following code, what is true about tax after amount = calculate_total(100, 0.08)?

def calculate_total(price, tax_rate):
tax = price * tax_rate
total = price + tax
return total

  1. A

    tax is local to calculate_total and is not directly accessible outside it.

  2. B

    tax is global because it is used in an arithmetic expression.

  3. C

    tax is automatically returned along with total.

  4. D

    tax can be accessed outside the function because all Python variables are global.

17
Choose one
1 point

How should this function be classified?

def add_score(scores, new_score):
scores.append(new_score)

  1. A

    It is pure because it accepts a list parameter.

  2. B

    It is pure because it performs only one operation.

  3. C

    It has no effect because it does not return a value.

  4. D

    It has a side effect because it modifies the caller's list.

18
True or false
1 point

True or false: In Python, defining a function normally executes its body immediately.

  1. A

    True

  2. B

    False

19
Written response
1 point

The function average(first, second, third) returns (first + second + third) / 3. What value does average(80, 90, 100) return? Enter the numerical average as a whole number.

20
Written response
1 point

What is the programming term for dividing a large problem into smaller subproblems, with each subproblem potentially implemented as a focused function? Enter the single programming term.