Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.
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
...
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 2 years, 6 months agodicksonpwc
Most Recent 12 months agoandr3
1 year ago9prayer
1 year, 2 months ago9prayer
1 year, 2 months agoJnanada
1 year, 8 months agomacxsz
1 year, 11 months agoNoarmy315
2 years, 3 months agoruydrigo
2 years, 4 months ago