nerdexam
Python_Institute

PCEP-30-02 · Question #388

What is the expected output of the following code? ``python def traverse(stop): if stop == 0: return 0 else: return stop * traverse(stop - 1) print(traverse(2)) ``

The correct answer is D. 1. See the full explanation below for the reasoning.

Question

What is the expected output of the following code?
def traverse(stop):
 if stop == 0:
 return 0
 else:
 return stop * traverse(stop - 1)
print(traverse(2))

Options

  • A2
  • B0
  • C3
  • D1

How the community answered

(33 responses)
  • A
    6% (2)
  • B
    12% (4)
  • C
    3% (1)
  • D
    79% (26)

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice