nerdexam
Python_Institute

PCEP-30-02 · Question #324

What is the expected output of the following code? my_list = [[3-i for i in range(3)] for j in range(3)] result = 0 for i in range(3): result += my_list[i][i] print(result)

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

Question

What is the expected output of the following code? my_list = [[3-i for i in range(3)] for j in range(3)] result = 0 for i in range(3): result += my_list[i][i] print(result)

Options

  • A6
  • B4
  • C7
  • D2

How the community answered

(35 responses)
  • A
    74% (26)
  • B
    14% (5)
  • C
    3% (1)
  • D
    9% (3)

Community Discussion

No community discussion yet for this question.

Full PCEP-30-02 Practice