Question

In: Computer Science

Run the  Python Queue Line Simulator  three times Python Queue Line """ File: pyQueueSim.py Author: JD """ import...

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

Solutions

Expert Solution

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


Related Solutions

''' File: pyPatientLL.py Author: JD ''' class Node: #ADT        def __init__(self, p = None):             ...
''' File: pyPatientLL.py Author: JD ''' class Node: #ADT        def __init__(self, p = None):              self.name = ""              self.ss = self.age = int(0)              self.smoker = self.HBP = self.HFD = self.points = int(0)              self.link = None              #if list not empty              if p != None:                     p.link = self        ptrFront = ptrEnd = None choice = int(0) def menu():        print( "\n\tLL Health Clinic\n\n")        print( "1. New patient\n")        print( "2. View patient by...
In python explain why would we want to read a file line by line instead of...
In python explain why would we want to read a file line by line instead of all at once?
What does each line of this python code do? import datetime import getpass print("\n\nFinished execution at...
What does each line of this python code do? import datetime import getpass print("\n\nFinished execution at ", datetime.datetime.now()) print(getpass.getuser())
I have an excel file imported into canopy (python) using import pandas as pd. The excel...
I have an excel file imported into canopy (python) using import pandas as pd. The excel file has headers titled: datetime created_at PM25 temperatureF dewpointF    humidityPCNT windMPH    wind_speedMPH wind_gustsMPH pressureIN precipIN these column headers all have thousands of data numbers under them. How could i find the average of all of the numbers in each column and plot them on 1 graph (line graph or scatter plot) Thank you.(please comment out your code)
Copy the following Python fuction discussed in class into your file: from random import * def...
Copy the following Python fuction discussed in class into your file: from random import * def makeRandomList(size, bound): a = [] for i in range(size): a.append(randint(0, bound)) return a a. Add another function that receives a list as a parameter and computes the sum of the elements of the list. The header of the function should be def sumList(a): The function should return the result and not print it. If the list is empty, the function should return 0. Use...
Write a single python file to perform the following tasks: (a) Get dataset “from sklearn.datasets import...
Write a single python file to perform the following tasks: (a) Get dataset “from sklearn.datasets import load_iris”. Split the dataset into two sets: 20% of samples for training, and 80% of samples for testing. NOTE 1: Please use “from sklearn.model_selection import train_test_split” with “random_state=N” and “test_size=0.80”. NOTE 2: The offset/bias column is not needed here for augmenting the input features. (b) Generate the target output using one-hot encoding for both the training set and the test set. (c) Using the...
Python 3 8.5 Open the file mbox-short.txt and read it line by line. When you find...
Python 3 8.5 Open the file mbox-short.txt and read it line by line. When you find a line that starts with 'From ' like the following line: From [email protected] Sat Jan 5 09:14:16 2008 You will parse the From line using split() and print out the second word in the line (i.e. the entire address of the person who sent the message). Then print out a count at the end. Hint: make sure not to include the lines that start...
Hi I have problem with run this JAVA file import java.io.*; public class DataPresenter { public...
Hi I have problem with run this JAVA file import java.io.*; public class DataPresenter { public static void main (String args []) { System.out.println("File:../SmallAreaIncomePovertyEstData.text"); System.out.println("Id" + "\t" + "Population" + "\t" + "ChildPop" + "\t" + "CPovPop" + "\t" + "CPovPop%"); }// read the data try (FileReader fr = new FileReader("File: C:\\605.201/SmallAreaIncomePovertyEstData.text")) { int c; while (( c = fr.read())!= -1){ System.out.print((char) c); } } catch(IOException e) { System.out.println("I/O Error" + e); }    } Please help to fix
(Python) In a weather station, there is a sensor that measures the temperature three times a...
(Python) In a weather station, there is a sensor that measures the temperature three times a day (in Celsius). Write a program that asks the user to input three numbers, corresponding to the sensor's three readings for a particular day. Then, print the minimum, maximum and average value of the three numbers. Note: If one or two inputs are either less than -70, or greater than +50 degrees, you should ignore those one or two inputs, and calculate the minimum,...
In Python please:  Number the Lines in a File: Create a program that adds line numbers to...
In Python please:  Number the Lines in a File: Create a program that adds line numbers to a file. The name of the input file will be read from the user, as will the name of the new file that your program will create. Each line in the output file should begin with the line number, followed by a colon and a space, followed by the line from the input file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT