A function compute_tax(amount) prints the tax value inside the function. A developer writes total = amount + compute_tax(amount) expecting total to hold the sum. What will actually happen?
Atotal will hold the correct sum because the printed value is captured automatically
Btotal will be None (or cause a TypeError) because compute_tax returns nothing, not the tax value
Ctotal will hold just the amount, since print is ignored in arithmetic expressions
Dtotal will hold the printed string concatenated with amount
print() displays text for humans — it does not send a value back into the program. A function that only prints has no explicit return, so it returns None. Using None in arithmetic with amount raises a TypeError (or in some languages produces undefined behavior). The fix is to replace print(tax) with return tax, so the caller receives the value it needs.
Question 2 Multiple Choice
Which of the following accurately describes what happens when Python executes a return statement inside a function?
AThe function displays the value and continues running any remaining statements
BThe function pauses execution and waits for the caller to request the value
CThe function immediately stops executing and sends the specified value back to the caller
DThe function stores the value in a global variable accessible to the caller
A return statement does two things simultaneously: it ends the function's execution at that point (no further lines in the function run), and it delivers the value back to the caller. This is why 'unreachable code' warnings appear for statements after a return — they will never execute. The caller receives the value directly and can use it in expressions, assign it to variables, or pass it to other functions.
Question 3 True / False
A function can contain more than one return statement, and the first one that is reached during execution will end the function.
TTrue
FFalse
Answer: True
Multiple return statements are valid and common — each is an independent exit point. Early returns are a standard pattern: for example, checking for invalid input at the top of a function and returning an error value before reaching the main logic. The function ends at whichever return is executed first during a given call.
Question 4 True / False
Printing a result inside a function and returning a result from a function are equivalent, because both make the value available to the rest of the program.
TTrue
FFalse
Answer: False
print() sends text to the screen for a human to read — the program itself cannot use that text for computation. A return statement sends the value back into the program's flow, where it can be stored in a variable, passed to another function, or used in an expression. A function that prints its result cannot be composed with other functions; a function that returns its result can. This distinction is fundamental to writing reusable, testable code.
Question 5 Short Answer
Why should a function that computes a result return it rather than print it?
Think about your answer, then reveal below.
Model answer: Returning a value keeps the caller in control of what to do with the result — store it, pass it to another function, compare it to a threshold, or print it if desired. Printing inside the function makes the decision for the caller and makes the function non-composable: its output cannot be fed into other computations. A function that returns is testable and reusable; a function that only prints is a dead end in the program's data flow.
The composability argument is the core insight. If circle_area() returns the area, you can write cylinder_volume = circle_area(r) * height. If it only prints, you cannot. Printing is a side effect for human consumption; returning is the mechanism by which functions contribute to program logic. Functions that compute should return — functions that exist solely for side effects (writing files, sending data) may legitimately return nothing.