PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 Exam - Question 58


Which of the following lines of code will work flawlessly when put independently inside the add_new() method in order to make the snippet's output equal to [0, 1, 2]? (Choose two.)

Show Answer
Correct Answer: AB

To achieve the output [0, 1, 2], we need to correctly append the next number in the sequence to the queue. Both 'self.queue.append(self.queue[-1] + 1)' and 'self.queue.append(self.get_last() + 1)' will add the next integer to the queue in the correct manner. The former directly accesses the last element using indexing, and the latter uses the method 'get_last()', which returns the last element. Both lines of code will work flawlessly to make the snippet's output equal to [0, 1, 2].

Discussion

1 comment
Sign in to comment
DKAT2023Options: AB
Jul 12, 2024

A and B are corrects