Completed
Return Values + Flow of Execution
Questions From This Challenge
Q1mcq1 mark
What does the return statement do in a function?
Prints a value to the screen
Sends a value back to the caller and ends the function's execution ✓
Deletes the function after execution
Declares a variable as global
Q2mcq1 mark
If a function does not contain a return statement, what value does calling it return by default?
0
"" (empty string)
None ✓
It causes an error
Q3mcq1 mark
In terms of flow of execution, what happens when a function is called?
The program continues in sequence and ignores the function
Control transfers to the function, its body executes, then control returns to the point right after the call ✓
The entire program restarts
The function executes independently in a separate program
Q4mcq1 mark
A function in Python can return:
Only a single value
Only integers
A single value, multiple values, or no value at all ✓
Nothing under any circumstance
Q5mcq1 mark
Consider:
def calc():
return 5
print("Done")
print(calc())
Which statement is true about this code?
"Done" is printed before 5
"Done" is never printed because return exits the function immediately ✓
The program raises an error
"Done" is printed after 5
Q6mcq1 mark
If function X calls function Y inside its body, what is the execution order?
Y always executes before X starts
X's statements before the call run, then Y fully executes, then X's remaining statements run ✓
X and Y execute simultaneously
Y never executes
Q7mcq1 mark
What value does a bare return statement (return with no value) send back?
0
an empty string
None ✓
False
Q8output1 mark
What is the output?
def add(a, b):
return a + b
result = add(3, 4)
print(result)
Correct output:
7Q9output1 mark
What is the output?
def square(n):
return n * n
print(square(5) + 1)
Correct output:
26Q10output1 mark
What is the output?
def test():
print("Start")
return 10
print("End")
value = test()
print(value)
Correct output:
Start
10Q11output1 mark
What is the output?
def first():
print("A")
second()
print("B")
def second():
print("C")
first()
Correct output:
A
C
BQ12output1 mark
What is the output?
def show():
print("Hello")
return
x = show()
print(x)
Correct output:
Hello
NoneQ13output1 mark
What is the output?
def minmax(a, b, c):
return min(a, b, c), max(a, b, c)
result = minmax(4, 9, 2)
print(result)
Correct output:
(2, 9)Q14output1 mark
What is the output?
def double(n):
return n * 2
def triple(n):
return n * 3
print(double(triple(2)))
Correct output:
12Q15output1 mark
What is the output?
def process(n):
print("Processing", n)
return n + 1
a = process(1)
b = process(a)
print(a, b)
Correct output:
Processing 1
Processing 2
2 3