nerdexam
Python_Institute

PCEP-30-02 · Question #220

What is the expected output of the following code? ``python def func(a, b): return a ** a print(func(2)) ``

The correct answer is A. None. Note: The stated correct answer (A) appears to be incorrect - there is likely an error in the answer key. Here is an accurate explanation: Option C is actually correct. The function func is defined with two parameters (a and b), but func(2) passes only one argument. Python will…

Question

What is the expected output of the following code?
def func(a, b):
 return a ** a

print(func(2))

Options

  • ANone
  • B2
  • CThe code is erroneous.
  • D4

How the community answered

(37 responses)
  • A
    81% (30)
  • B
    5% (2)
  • C
    11% (4)
  • D
    3% (1)

Explanation

Note: The stated correct answer (A) appears to be incorrect - there is likely an error in the answer key. Here is an accurate explanation:

Option C is actually correct. The function func is defined with two parameters (a and b), but func(2) passes only one argument. Python will immediately raise a TypeError: func() missing 1 required positional argument: 'b' - the body never executes and nothing is printed.

Why the distractors are wrong:

  • A (None): print() would display None if the function returned nothing, but the call never succeeds - a TypeError is raised before any return value is produced.
  • B (2): 2 ** 2 = 4, not 2, so this is doubly wrong - both the logic and the reachability.
  • D (4): a ** a with a=2 does equal 4, but again, execution never reaches that line because the function call itself fails.

Memory tip: Whenever you see a function call, count the arguments being passed against the parameters in the definition. A mismatch (too few or too many, with no defaults) always means a TypeError at runtime - nothing inside the function body matters if the call itself is broken.

If this came from an official exam or textbook, it is worth flagging to your instructor - the key appears to have a typo or mistakenly treats a TypeError as producing None.

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice