GATE DA 2024 · Programming in Python

MCQ · 2 marks · Problem PROG-PYBS-0001

Consider the following Python code:
def count(child_dict, i):
    if i not in child_dict.keys():
         return 1
    ans = 1
    for j in child_dict[i]:
        ans += count(child_dict, j)
    return ans
child_dict = dict()
child_dict[0] = [1,2]
child_dict[1] = [3,4,5]
child_dict[2] = [6,7,8]
print(count(child_dict,0))
Which ONE of the following is the output of this code?
  1. A
    6
  2. B
    1
  3. C
    8
  4. D
    9

Solve it on GATE DA practice →More Python Programming problems

Show the worked solutionOfficial GATE Answer Key: Option D.See full step-by-step discussion on GateOverflow: https://gateoverflow.in/422934/gate-ds%26ai-2024-question-28

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com