Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCEP-30-02 All Questions

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

Exam PCEP-30-02 topic 1 question 20 discussion

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

What is the output of the following snippet?

  • A. [1, 1, 2, 2]
  • B. [1, 1, 1, 2]
  • C. [1, 2, 1, 2]
  • D. [1, 2, 2, 2]
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
consultsk
1 month, 3 weeks ago
Selected Answer: B
Let's step through this code to understand what's happening: We start with my_list = [1, 2] The loop for v in range(2): will run twice, with v taking values 0 and 1. In each iteration, we're using my_list.insert(-1, my_list[v]): insert(-1, ...) means insert at the second-to-last position my_list[v] is the element we're inserting Let's go through the iterations: First iteration (v = 0): We insert my_list[0] (which is 1) at index -1 my_list becomes [1, 1, 2] Second iteration (v = 1): We insert my_list[1] (which is now 1) at index -1 my_list becomes [1, 1, 1, 2] After the loop, we print my_list Therefore, the output will be: [1,1,1,2]
upvoted 1 times
...
megan_mai
3 months ago
Selected Answer: B
my_list = [1,2] for v in range (2): my_list.insert(-1,my_list[v]) >>> loop 1: v=0 >> insert my_list[0] in the position my_list[-1] >> my_list = [1,1,2] >>> loop 2: v=1 >> insert my_list[1] in the position my_list[-1] >> my_list = [1,1,1,2] print(my_list) >>>> [1,1,1,2] (B)
upvoted 1 times
...
christostz03
3 months ago
b is the correct answer
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 ...