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)- A6% (2)
- B12% (4)
- C3% (1)
- D79% (26)
Community Discussion
No community discussion yet for this question.