PCEP-30-02 · Question #196
The following snippet: def function_1(a): return None def function_2(a): return function_1(a) * function_1(a) print(function_2(2))
The correct answer is A. will cause a runtime error. Option A is correct because function_1 always returns None, so function_2 attempts to evaluate None None - Python cannot multiply None values and raises a TypeError at runtime. Options B and C are wrong because they assume function_1 returns the argument a (which would give…
Question
Options
- Awill cause a runtime error
- Bwill output 4
- Cwill output 16
- Dwill output 2
How the community answered
(49 responses)- A73% (36)
- B8% (4)
- C4% (2)
- D14% (7)
Explanation
Option A is correct because function_1 always returns None, so function_2 attempts to evaluate None * None - Python cannot multiply None values and raises a TypeError at runtime. Options B and C are wrong because they assume function_1 returns the argument a (which would give 2*2=4 or 4*4=16), but it explicitly returns None, not a. Option D is similarly wrong for the same reason - 2 is the input, not the output. Memory tip: Whenever you see return None (or an empty return), mentally replace every call to that function with the word None and ask yourself if the surrounding expression makes sense - multiplying, adding, or comparing None almost always triggers a runtime error.
Community Discussion
No community discussion yet for this question.