What normally happens when Python executes a function definition such as def greet(): print("Hello!")?
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.
True or false: In def greet_person(name): ..., name is a parameter, while in greet_person("Maya"), "Maya" is an argument.
- A
True
- B
False
What programming term names the variable in a function definition that receives a value supplied by the caller?
Complete the statement: If a Python function reaches the end without returning a value, it returns .
In the function def square(number): ..., which statement makes the squared value available to the code that called the function?
- A
print(number * number) - B
result = number * number - C
return number * number - D
number = number * number
Given def power(base, exponent=2): return base ** exponent, select all correct statements.
- A
power(5)returns 25. - B
power(5)returns 125. - C
power(5, 3)returns 125. - D
power(5, 3)returns 25.
True or false: If a function executes a return statement, a later statement in that same function body will still execute normally.
- A
True
- B
False
In the material's abstraction example, what is the exact function name that lets a caller test whether a number is divisible by 2?
Complete the statement: A function that modifies the list supplied by its caller produces a .
Which statement best describes the variable tax created inside calculate_total(price, tax_rate)?
- A
A variable created inside a function is automatically global.
- B
A variable created inside a function is usually local to that function call.
- C
A local variable can be accessed from any function in the program.
- D
A local variable exists only while the program is being defined.
In the decomposition example with weighted_score, letter_grade, and report_result, select all accurate descriptions of the functions' responsibilities.
- A
weighted_scorecalculates the weighted numerical score. - B
letter_gradecalculates the weighted numerical score. - C
letter_gradedetermines the letter category from a score. - D
report_resultcoordinates the smaller operations.
Explain what happens when this code runs, and why: def double_and_print(number): print(number * 2) followed by result = double_and_print(4).
Which design choice best makes a function's dependencies visible and supports testing?
- A
Pass required data as parameters and return results explicitly.
- B
Use global variables so every function can access the same data.
- C
Put all calculations into one large function to avoid communication between functions.
- D
Hide required inputs in unrelated local variables.
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?
- A
nameis the argument and"Maya"is the parameter. - B
nameis the parameter and"Maya"is the argument. - C
Both
nameand"Maya"are parameters. - D
Both
nameand"Maya"are arguments.
What happens when this function is called as result = choose()?
def choose(): return 7 print(9)
- A
The function prints 7 and then returns
None. - B
The function prints both 7 and 9.
- C
The function returns 7 and does not print 9.
- D
The function returns 9 because it is the last expression.
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
- A
taxis local tocalculate_totaland is not directly accessible outside it. - B
taxis global because it is used in an arithmetic expression. - C
taxis automatically returned along withtotal. - D
taxcan be accessed outside the function because all Python variables are global.
How should this function be classified?
def add_score(scores, new_score): scores.append(new_score)
- A
It is pure because it accepts a list parameter.
- B
It is pure because it performs only one operation.
- C
It has no effect because it does not return a value.
- D
It has a side effect because it modifies the caller's list.
True or false: In Python, defining a function normally executes its body immediately.
- A
True
- B
False
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.
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.