0
0
Intro to Computingfundamentals~10 mins

Queues (first-in, first-out) in Intro to Computing - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add an item to the end of the queue.

Intro to Computing
queue = []
queue.[1]('apple')
Drag options to blanks, or click blank then click option'
Apop
Bappend
Cremove
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pop' removes an item instead of adding.
Using 'remove' deletes a specific item, not add.
Using 'insert' needs an index and is more complex.
2fill in blank
medium

Complete the code to remove the first item from the queue.

Intro to Computing
queue = ['apple', 'banana', 'cherry']
first_item = queue.[1](0)
Drag options to blanks, or click blank then click option'
Apop
Bappend
Cremove
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'append' adds items instead of removing.
Using 'remove' needs the item value, not index.
Using 'insert' adds items, not removes.
3fill in blank
hard

Fix the error in the code to correctly remove the first item from the queue.

Intro to Computing
queue = ['dog', 'cat', 'bird']
removed = queue.[1]
Drag options to blanks, or click blank then click option'
Adelete(0)
Bpop
Cremove(0)
Dpop(0)
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'pop()' removes the last item, not the first.
Using 'remove(0)' causes an error because remove expects a value.
Using 'delete(0)' is not a valid list method.
4fill in blank
hard

Fill both blanks to create a queue comprehension that keeps only items longer than 3 characters.

Intro to Computing
queue = ['cat', 'lion', 'dog', 'tiger']
filtered = [item for item in queue if len(item) [1] [2]]
Drag options to blanks, or click blank then click option'
A>
B3
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' keeps shorter items, not longer.
Using '==' keeps only items exactly length 3.
Swapping the number and operator causes wrong filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary showing each item and its position in the queue.

Intro to Computing
queue = ['red', 'blue', 'green']
positions = [1]: [2] for [3], color in enumerate(queue)}
Drag options to blanks, or click blank then click option'
A{color
Bindex
Dcolor
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping key and value reverses the dictionary.
Using wrong variable names causes errors.
Missing braces or colons breaks syntax.