In: Computer Science
Run the Python Queue Line Simulator three times
Python Queue Line
"""
File: pyQueueSim.py
Author: JD
"""
import random
print("Queue as a customer line\n")
queue = [] # Empty que
y = int(0)
# Queue up some customers
for i in range(1,20):
x = random.randint(1, 20)
if x >= 2 and x<= 8:
queue.append(x) # Add to the front
# Simulate cumstomer line processing
while True:
x = random.randint(1, 20)
if x >= 2 and x<= 8:
queue.append(x *2) # Add to the front
print("Queued :", x)
elif x >=9 and x <=14 and len(queue)>0:
y = queue.pop(0)
print ("Removed: ",y)
elif x == 17 and len(queue)>=10:
print ("Line closing\n")
while len(queue)>0:
y =
queue.pop(0)
print ("Removed: ",y)
break
Queue as a customer line
Queued : 3
Removed: 8
Queued : 7
Queued : 4
Removed: 7
Removed: 6
Removed: 7
Removed: 2
Removed: 2
Removed: 5
Queued : 4
Removed: 4
Queued : 3
Removed: 7
Removed: 6
Queued : 6
Removed: 14
Queued : 5
Removed: 8
Removed: 8
Removed: 6
Queued : 3
Queued : 5
Removed: 12
Queued : 4
Queued : 3
Queued : 3
Queued : 4
Queued : 4
Queued : 5
Queued : 6
Removed: 10
Removed: 6
Queued : 4
Queued : 5
Removed: 10
Removed: 8
Removed: 6
Removed: 6
Removed: 8
Queued : 4
Queued : 8
Queued : 2
Removed: 8
Queued : 8
Queued : 3
Queued : 8
Queued : 7
Removed: 10
Queued : 6
Removed: 12
Removed: 8
Queued : 8
Queued : 8
Queued : 4
Removed: 10
Queued : 4
Removed: 8
Removed: 16
Queued : 5
Removed: 4
Queued : 2
Queued : 2
Queued : 5
Removed: 16
Queued : 4
Line closing
Removed: 6
Removed: 16
Removed: 14
Removed: 12
Removed: 16
Removed: 16
Removed: 8
Removed: 8
Removed: 10
Removed: 4
Removed: 4
Removed: 10
Removed: 8
Press any key to continue . . .
IN PYTHON THANKS
since this code is working fine.
it is executed three times as you specified in the question.
here by i am attaching screenshot of properly intended code and output obtained in three stimulations.
import random
print("Queue as a customer line\n")
queue = [] # Empty queue
y = int(0)
# Queue up some customers
for i in range(1,20):
x = random.randint(1, 20)
if x >= 2 and x<= 8:
queue.append(x) # Add to the front
# Simulate cumstomer line processing
while True:
x = random.randint(1, 20)
if x >= 2 and x<= 8:
queue.append(x *2) # Add to the front
print("Queued :", x)
elif x >=9 and x <=14 and len(queue)>0:
y = queue.pop(0)
print ("Removed: ",y)
elif x == 17 and len(queue)>=10:
print ("Line closing\n")
while len(queue)>0:
y = queue.pop(0)
print ("Removed: ",y)
break
output1:
Queue as a customer line
Queued : 8
Queued : 3
Removed: 7
Queued : 5
Queued : 7
Queued : 6
Removed: 4
Removed: 3
Removed: 2
Removed: 7
Removed: 6
Queued : 8
Queued : 6
Removed: 8
Queued : 7
Queued : 7
Removed: 8
Removed: 6
Removed: 3
Queued : 6
Queued : 5
Queued : 6
Removed: 16
Queued : 7
Line closing
Removed: 6
Removed: 10
Removed: 14
Removed: 12
Removed: 16
Removed: 12
Removed: 14
Removed: 14
Removed: 12
Removed: 10
Removed: 12
Removed: 14
...Program finished with exit code 0
Press ENTER to exit console.
output 2:
Queue as a customer line
Queued : 4
Queued : 3
Removed: 2
Queued : 7
Queued : 6
Line closing
Removed: 2
Removed: 3
Removed: 2
Removed: 2
Removed: 6
Removed: 4
Removed: 6
Removed: 2
Removed: 2
Removed: 8
Removed: 5
Removed: 8
Removed: 6
Removed: 14
Removed: 12
...Program finished with exit code 0
Press ENTER to exit console.
output 3:
Queue as a customer line
Queued : 4
Removed: 7
Removed: 5
Queued : 2
Removed: 3
Removed: 7
Queued : 4
Queued : 5
Removed: 3
Queued : 2
Queued : 4
Queued : 8
Removed: 8
Queued : 7
Line closing
Removed: 5
Removed: 8
Removed: 8
Removed: 8
Removed: 4
Removed: 8
Removed: 10
Removed: 4
Removed: 8
Removed: 16
Removed: 14
...Program finished with exit code 0
Press ENTER to exit console.
i hope the answer is clear and satisfactory
if you have any doubts feel free to ask in comment section
please give me a thumbs up