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())
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...
CODE BLOCK E import csv filename = "D:/python/Week8/files/green.csv" with open(filename) as file: data_from_file = csv.reader(file) header_row...
CODE BLOCK E import csv filename = "D:/python/Week8/files/green.csv" with open(filename) as file: data_from_file = csv.reader(file) header_row = next(data_from_file) for index,column_header in enumerate(header_row): print(index,column_header) How many COUMNS (not rows!) will be printed in the above code?
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
in PYTHON given a specific text file containing a list of numbers on each line (numbers...
in PYTHON given a specific text file containing a list of numbers on each line (numbers on each line are different) write results to a new file after the following tasks are performed: Get rid of each line of numbers that is not 8 characters long Get rid of lines that don't begin with (478, 932, 188, 642, 093)
(PYTHON) Write a program that does the following: reads each line from a txt file and...
(PYTHON) Write a program that does the following: reads each line from a txt file and convert it to lowercase counts the number of instances of: the characters 'a', 'e','i','o' and 'u' in the file creates a new file of file type .vowel_profile print outs lines in the file indicating the frequencies of each of these vowels Example input/output files: paragraph_from_wikipedia.txt (sample input) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.txt paragraph_from_wikipedia.vowel_profile (sample output) link: https://cs.nyu.edu/courses/fall19/CSCI-UA.0002-007/paragraph_from_wikipedia.vowel_profile Please help!
On Python Preview the provided sample file called studentdata.txt. It contains one line for each student...
On Python Preview the provided sample file called studentdata.txt. It contains one line for each student in an imaginary class. The student’s name is the first thing on each line, followed by some exam scores. The number of scores might be different for each student. Using the text file studentdata.txt write a program that calculates the average grade for each student, and print out the student’s name along with their average grade with two decimal places.
IN PYTHON File Data --- In file1.txt add the following numbers, each on its own line...
IN PYTHON File Data --- In file1.txt add the following numbers, each on its own line (20, 30, 40, 50, 60). Do not add data to file2.txt. Write a program. Create a new .py file that reads in the data from file1 and adds all together. Then output the sum to file2.txt. Add your name to the first line in file2.txt (see sample output) Sample Output Your Name 200 use a main function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT