nerdexam
Python_Institute

PCEP-30-02 · Question #33

What is the expected output of the following code? ``python data = {1: 0, 2: 1, 3: 2, 0: 1} x = 0 for _ in range(len(data)): x = data[x] print(x) ``

The correct answer is A. 0. See the full explanation below for the reasoning.

Question

What is the expected output of the following code?
data = {1: 0, 2: 1, 3: 2, 0: 1}
x = 0
for _ in range(len(data)):
 x = data[x]
print(x)

Options

  • A0
  • B1
  • CThe code is erroneous.
  • D2

How the community answered

(49 responses)
  • A
    84% (41)
  • B
    10% (5)
  • C
    2% (1)
  • D
    4% (2)

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice