PCEP-30-02 · Question #174
What is the expected output of the following code? ``python def func1(param): return param def func2(param): return param * 2 def func3(param): return param + 3 print(func1(func2(func3(1)))) ``
The correct answer is C. 8. Evaluating nested function calls works inside-out: func3(1) runs first, returning 1 + 3 = 4; then func2(4) returns 4 2 = 8; finally func1(8) simply returns 8 unchanged - so print() outputs 8. Why the distractors fail: A (3) ignores the multiplication - it's only func3(1) with…
Question
def func1(param):
return param
def func2(param):
return param * 2
def func3(param):
return param + 3
print(func1(func2(func3(1))))
Options
- A3
- B6
- C8
- D1
How the community answered
(17 responses)- A12% (2)
- C82% (14)
- D6% (1)
Explanation
Evaluating nested function calls works inside-out: func3(1) runs first, returning 1 + 3 = 4; then func2(4) returns 4 * 2 = 8; finally func1(8) simply returns 8 unchanged - so print() outputs 8.
Why the distractors fail:
- A (3) ignores the multiplication - it's only
func3(1)with no further processing. - B (6) incorrectly doubles the original input (
1 * 2 * 3 = 6), as if the functions ran independently or in a different order. - D (1) is the raw input, as if none of the transformations were applied.
Memory tip: When you see nested calls, mentally replace each function from the innermost parenthesis outward - think of it as peeling an onion, one layer at a time: +3 first, then ×2, then "pass through."
Community Discussion
No community discussion yet for this question.