nerdexam
Python_Institute

PCEP-30-02 · Question #183

The following snippet: def func(a, b): return a ** a print(func(2))

The correct answer is C. is erroneous. Option C is correct because func is defined with two parameters (a and b), but is called with only one argument (func(2)). Python raises a TypeError at runtime: "func() missing 1 required positional argument: 'b'", so the program never executes at all. Why the distractors fail…

Question

The following snippet: def func(a, b): return a ** a print(func(2))

Options

  • Awill output 4
  • Bwill output 2
  • Cis erroneous
  • Dwill return None

How the community answered

(26 responses)
  • A
    8% (2)
  • B
    12% (3)
  • C
    77% (20)
  • D
    4% (1)

Explanation

Option C is correct because func is defined with two parameters (a and b), but is called with only one argument (func(2)). Python raises a TypeError at runtime: "func() missing 1 required positional argument: 'b'", so the program never executes at all.

Why the distractors fail:

  • A (output 4) and B (output 2) both assume the function runs successfully - it doesn't, because the missing argument causes a crash before the return line is ever reached. (If it did run with a=2, a ** a would be 2 ** 2 = 4, but the b parameter being unused is a red herring.)
  • D (return None) would apply if the function had no return statement - but that's irrelevant here since execution never gets that far.

Memory tip: Always count the commas. If a function signature has one comma (def func(a, b)), it needs two arguments at the call site - one more than the number of commas.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice