PCEP-30-02 · Question #202
What is the expected output of the following code? def fun(n): n **= n return n print(fun(3))
The correct answer is D. 27. Option D is correct because = is Python's exponentiation assignment operator, making n = n equivalent to n = n n - so with n = 3, this computes 3 3 = 27, which is then returned and printed. Why the distractors fail: A (9) is the result of 3 3 or 3 2 - a common confusion…
Question
Options
- A9
- BThe program will cause an error.
- CTrue
- D27
- E3
How the community answered
(66 responses)- A12% (8)
- B3% (2)
- C8% (5)
- D76% (50)
- E2% (1)
Explanation
Option D is correct because **= is Python's exponentiation assignment operator, making n **= n equivalent to n = n ** n - so with n = 3, this computes 3 ** 3 = 27, which is then returned and printed.
Why the distractors fail:
- A (9) is the result of
3 * 3or3 ** 2- a common confusion mistaking**(exponentiation) for*(multiplication), or misreading the exponent as 2 instead of 3. - B (error) is wrong because the code is syntactically and logically valid - Python handles
**=without issue. - C (True) would only appear if a boolean comparison (e.g.,
==) were involved; no such comparison exists here. - E (3) would be correct only if the function returned
nbefore modifying it, but the modification happens first.
Memory tip: Read **= as "raise to the power of itself" - n **= n means n becomes n-to-the-n, so always ask: "base and exponent are the same number." For 3, that's 3³ = 27, not 3².
Community Discussion
No community discussion yet for this question.