Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

A first-in-first-out (FIFO) structure, also called a “queue,” is a list that gets new elements added at the end, while elements from the front are removed and processed. Write a program that processes a queue. In a loop, ask the user for input. If the user just presses the Enter key, the program ends. If the user enters anything else, except for a single question mark (?), the program considers what the user entered a new element and appends it to the queue. If the user enters a single question mark, the program pops the first element from the queue and displays it. You have to take into account that the user might type a question mark even if the queue is empty.

Assignment

Represent a queue as a list (list) of strings (str), and write the following three functions.

Example

>>> queue = ['apple', 'pear']
>>> push(queue, 'fig')
>>> queue
['apple', 'pear', 'fig']
>>> pop(queue)
'apple'
>>> queue
['pear', 'fig']
>>> process(['apple', 'pear', '?', 'fig', '?', '?', '?', '', 'plum'])
apple
pear
fig
The queue is empty.