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 58 discussion

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

What is the expected output of the following code?

  • A. [4, 3, 2, 1]
  • B. [4, 3, 2]
  • C. [4, 3]
  • D. The code is erroneous.
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

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
hovnival
1 day, 21 hours ago
Selected Answer: B
Initial List The initial list a is [1, 2, 3, 4, 5]. Slicing Operation The slicing operation is a[3:0:-1]. The slicing syntax is list[start:stop:step]: start is the index where the slice starts (inclusive). stop is the index where the slice ends (exclusive). step is the step size or the direction of the slice. In this case: start is 3, so the slice starts at index 3 (the element 4). stop is 0, so the slice ends before index 0 (the element 1), and since the step is negative, it will not include the element at index 0. step is -1, so the slice moves backward. Extracting Elements Following the slicing operation a[3:0:-1]: Start at index 3 (the element 4). Move backward with a step of -1. Stop before reaching index 0. The elements included in the slice are: a[3] is 4 a[2] is 3 a[1] is 2 Therefore, the resulting sliced list is [4, 3, 2]. Output [4, 3, 2]
upvoted 1 times
...
christostz03
4 months, 1 week 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 ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago