Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCAP All Questions

View all questions & answers for the PCAP exam

Exam PCAP topic 1 question 104 discussion

Actual exam question from Python Institute's PCAP
Question #: 104
Topic #: 1
[All PCAP Questions]

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.)

  • A. self.queue.append(self.get_last() + 1)
  • B. self.queue.append(get_last() + 1)
  • C. self.queue.append(self.queue[-1] + 1)
  • D. queue.append(self.get_last() + 1)
Show Suggested Answer Hide Answer
Suggested Answer: AC 🗳️

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
vlobachevsky
Highly Voted 3 years, 1 month ago
AC is correct
upvoted 7 times
...
dicksonpwc
Most Recent 1 year, 7 months ago
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
upvoted 2 times
...
andr3
1 year, 8 months ago
Selected Answer: AC
def add_new(self): self.queue.append(self.get_last() + 1) self.queue.append(self.queue[-1] + 1)
upvoted 1 times
...
9prayer
1 year, 9 months ago
Selected Answer: AC
AC is correct
upvoted 1 times
...
9prayer
1 year, 9 months ago
Selected Answer: AC
AC is correct
upvoted 1 times
...
Jnanada
2 years, 3 months ago
Correct answer should be AC
upvoted 1 times
...
macxsz
2 years, 6 months ago
Selected Answer: AC
A. self.queue.append(self.get_last() + 1) C. self.queue.append(self.queue[-1] + 1)
upvoted 2 times
...
Noarmy315
2 years, 10 months ago
AC is correct
upvoted 1 times
...
ruydrigo
2 years, 11 months ago
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
...
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 ...