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.)
self.queue.append(self.get_last() + 1) # ans A, return [0, 1, 2]
self.queue.append(get_last()+1) # ans B, show NameError at line 108:
# name 'get_last' is not defined
self.queue.append(self.queue[-1] + 1) # ans C, return [0, 1, 2]
queue.append(self.get_last() + 1) # ans D, IndentationError: expected an indented block
#after function definition on line 105
Correct answer should be A, C
class MyClass:
def __init__(self,size):
self.queue = [i for i in range(size)]
def get(self):
return self.queue
def get_last(self):
return self.queue[-1]
def add_new(self):
#self.queue.append(self.get_last()+1) ##[0, 1, 2]
#self.queue.append(get_last()+1) ##Error
#self.queue.append(self.queue[-1] + 1) ##[0, 1, 2]
#queue.append(self.get_last() + 1) ##Error
Object = MyClass(2)
Object.add_new()
print(Object.get())
A & C are correct
upvoted 4 times
...
This section is not available anymore. Please use the main Exam Page.PCAP Exam Questions
Log in to ExamTopics
Sign in:
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.
vlobachevsky
Highly Voted 3 years, 7 months agodicksonpwc
Most Recent 2 years agoandr3
2 years, 1 month ago9prayer
2 years, 3 months ago9prayer
2 years, 3 months agoJnanada
2 years, 8 months agomacxsz
3 years agoNoarmy315
3 years, 3 months agoruydrigo
3 years, 5 months ago