exam questions

Exam PCEP-30-02 All Questions

View all questions & answers for the PCEP-30-02 exam

Exam PCEP-30-02 topic 7 question 40 discussion

Actual exam question from Python Institute's PCEP-30-02
Question #: 40
Topic #: 7
[All PCEP-30-02 Questions]

What is the expected output of the following code?

  • A. 6
  • B. 4
  • C. 7
  • D. 2
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
4ba36e7
1 month, 3 weeks ago
Selected Answer: A
[3 - i for i in range(3)] i = 0 → 3 - 0 = 3 i = 1 → 3 - 1 = 2 i = 2 → 3 - 2 = 1 So the inner list is [3, 2, 1] [[3 - i for i in range(3)] for j in range(3)] The outer comprehension repeats the inner list 3 times my_list = [ [3, 2, 1], [3, 2, 1], [3, 2, 1] ] for i in range(3): result += my_list[i][i] i = 0 → my_list[0][0] = 3 → result = 3 i = 1 → my_list[1][1] = 2 → result = 5 i = 2 → my_list[2][2] = 1 → result = 6 A. 6
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...