Exam PCAP-31-03 All QuestionsBrowse all questions from this 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.)

    Correct Answer: A, B

    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
DKAT2023Options: AB

A and B are corrects