nerdexam
Python_Institute

PCEP-30-02 · Question #328

What is the expected output of the following code? data = [1, {}, (2, ), (), { }, [4, 5]] points = 0 for i in range(len(data)): if type(data[i]) == list: points += 1 elif type(data[i]) == tuple…

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

Question

What is the expected output of the following code? data = [1, {}, (2, ), (), { }, [4, 5]] points = 0 for i in range(len(data)): if type(data[i]) == list: points += 1 elif type(data[i]) == tuple: points += 10 elif type(data[i]) == set: points += 100 elif type(data[i]) == dict: points += 1000 else: points += 10000 print(points)

Options

  • A10221
  • B1024
  • C11112
  • D11121
  • E21102

How the community answered

(20 responses)
  • A
    15% (3)
  • B
    5% (1)
  • C
    10% (2)
  • D
    70% (14)

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice