Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an element to the end of a queue using a list.
DSA Python
queue = [] queue.append([1]) print(queue)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using insert(0, element) instead of append to add to the queue.
Trying to use pop() to add elements.
✗ Incorrect
The append method adds the element to the end of the list, simulating enqueue in a queue.
2fill in blank
mediumComplete the code to remove the first element from a queue using a list.
DSA Python
queue = ['apple', 'banana', 'cherry'] removed = queue.[1](0) print(removed) print(queue)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove() which removes by value, not index.
Using pop() without an index, which removes the last element.
✗ Incorrect
pop(0) removes and returns the first element, simulating dequeue in a queue.
3fill in blank
hardFix the error in the code to add an element to the top of a stack using a list.
DSA Python
stack = ['a', 'b', 'c'] stack.[1]('d') print(stack)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using push() which is not a list method in Python.
Using insert() which adds at a specific position, not necessarily the top.
✗ Incorrect
append() adds an element to the end of the list, which is the top of the stack.
4fill in blank
hardFill both blanks to remove the top element from a stack and print it.
DSA Python
stack = ['x', 'y', 'z'] top = stack.[1]() print(top) print(stack[[2]])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop(0) which removes the first element, not the top of the stack.
Using append() instead of pop().
✗ Incorrect
pop() removes the last element (top of stack). Using -1 index accesses the last element.
5fill in blank
hardFill all three blanks to create a queue using collections.deque, add an element, and remove the first element.
DSA Python
from collections import deque queue = deque() queue.[1]('first') queue.[2]('second') removed = queue.[3]() print(removed) print(list(queue))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pop() which removes from the right end, not the front.
Using appendleft() which adds to the front, not the end.
✗ Incorrect
append() adds to the right end of the deque (end of queue). popleft() removes from the left end (front of queue).