Certainly! Below is a Python script that models a queue system for the shop. This script includes the names of the people who signed up in chronological order, displays the current queue status, and highlights the next person in line whose order is ready.
# queueactivity.py
class Queue:
def __init__(self):
# Initialize an empty list to hold the queue
self.items = []
def enqueue(self, item):
# Add an item to the end of the queue
self.items.append(item)
def dequeue(self):
# Remove and return the item from the front of the queue
if not self.is_empty():
return self.items.pop(0)
else:
return None
def is_empty(self):
# Check if the queue is empty
return len(self.items) == 0
def size(self):
# Return the number of items in the queue
return len(self.items)
def peek(self):
# Return the item at the front of the queue without removing it
if not self.is_empty():
return self.items[0]
else:
return None
# Step 1: Create the Queue
shop_queue = Queue()
# List of people who signed up to purchase the item
sign_ups = [
"Howard Jefferson",
"Philip Jordan",
"Margaret Kelly",
"Irvin Shaw",
"Loretta Cabrera",
"Ron Gomez",
"Cecil Davis",
"Jack Ludington",
"Leona Terry",
"Delbert Bailey"
]
# Enqueue each name to the queue
for name in sign_ups:
shop_queue.enqueue(name)
# Step 2: Create the Display
# Printing the number of people in line
print(f"There are currently {shop_queue.size()} people in line waiting to order.")
# Displaying the next person's order status
next_person = shop_queue.peek()
print(f"Attention {next_person} - your order is ready.")
Explanation of the Code:
-
Queue Class: This defines a basic queue structure with methods to
enqueue
(add people),dequeue
(remove people), check if the queue isempty
, get the size of the queue, and peek at the front of the queue. -
Initialization: The
shop_queue
instance of theQueue
class is created. -
Sign-ups List: A list of signed-up customers is created in chronological order.
-
Enqueue Operation: The script iteratively adds each person's name to the queue using the
enqueue
method in a loop. -
Display Output: Finally, the program prints the total number of people in the queue and informs the next customer that their order is ready.
Running the Code
You can save this code to queueactivity.py
in PythonAnywhere and run it to see the output as per your requirement.