def __init__(self, theAnimator, colorOn=cOnQueue, colorOff=cRemovedFromQueue): """ theAnimator will usually be the GraphDisplay(Frame/Toplevel) """ Queue.__init__(self) self.Animator = theAnimator self.ColorOn = colorOn self.ColorOff = colorOff self.lastRemoved = None
#validating python version import sys if sys.version_info[0] < 3: print( "Error: You must use Python 3, try running $ python3 app.py or updating the python interpreter" ) #their exercise code starts here import json from DataStructures import Queue # their queue has to be declared globally (outside any other function) # that way all methods have access to it queue = Queue(mode="FIFO", current_queue=[]) def show_main_menu(): print(''' What would you like to do (type a number and press Enter)? - Type 1: For adding someone to the Queue. - Type 2: For removing someone from the Queue. - Type 3: For printing the current Queue state. - Type 4: To export the queue to the queue.json file. - Type 5: To import the queue from the queue.json file. - Type 6: To quit ''') response = input() return response def print_queue():
import json from DataStructures import Queue from sms import send # there queue has to be declared globally (outside any other function) # that way all methods have access to it queue = Queue(mode="FIFO") def print_queue(): # you must print on the console the entire queue list print("Printing the entire list...") print(queue.get_queue()) def add(name): queue.enqueue(name) return queue pass def dequeue(name): queue.dequeue(name) return queue pass def save(): pass
import json from DataStructures import Queue from sms import send lista = [] # there queue has to be declared globally (outside any other function) # that way all methods have access to it queue = Queue(mode="LIFO",current_queue= lista) def print_queue(): # you must print on the console the entire queue list print("Printing the entire list...") print(queue.get_queue()) def add(nombre): queue.enqueue(nombre) x = queue.size() - 1 send(nombre + ' tienes '+ str(x) + ' personas por delante') pass def dequeue(): send(queue.dequeue() + ' Ven a comer') pass def save(): file = open('lista.json','w+') file.write(json.dumps(queue.get_queue())) file.close() pass def load(ruta):
#validating python version import sys if sys.version_info[0] < 3: print( "Error: You must use Python 3, try running $ python3 app.py or updating the python interpreter" ) #their exercise code starts here import json from DataStructures import Queue # there queue has to be declared globally (outside any other function) # that way all methods have access to it queue = Queue(mode="FIFO", current_queue=['Sam', 'Frodo', 'Pippin']) def show_main_menu(): print(''' What would you like to do (type a number and press Enter)? - Type 1: For adding someone to the Queue. - Type 2: For removing someone from the Queue. - Type 3: For printing the current Queue state. - Type 4: To export the queue to the queue.json file. - Type 5: To import the queue from the queue.json file. - Type 6: To quit ''') response = input() return response def print_queue():
def __init__(self): self.queue1 = Queue.Queue() self.queue2 = Queue.Queue() #Maintain current no of elements self.curr_size = 0
#validating python version import sys if sys.version_info[0] < 3: print( "Error: You must use Python 3, try running $ python3 app.py or updating the python interpreter" ) #their exercise code starts here import json from DataStructures import Queue # there queue has to be declared globally (outside any other function) # that way all methods have access to it queue = Queue(mode='FIFO', current_queue=['bob', 'kate', 'rick', 'romeo', 'juliet']) def show_main_menu(): print(''' What would you like to do (type a number and press enter)? - Type 1: For adding someone to the Queue. - Type 2: For removing someone from the Queue. - Type 3: For printing the current Queue state. - Type 4: To export the queue to the queue.json file. - Type 5: To import the queue from the queue.json file. - Type 6: To quit ''') response = input() return response
#This assignment needs DataStructures.py file in your package, you can get it from resources page from DataStructures import Queue def check_numbers(number_queue): #write your logic here lent = number_queue.get_max_size() solution_queue1 = Queue(lent) while not number_queue.is_empty(): data = number_queue.dequeue() count = 0 for i in range(1, 11): if data % i == 0: count += 1 if count == 10: solution_queue1.enqueue(data) return solution_queue1 #Add different values to the queue and test your program number_queue = Queue(5) number_queue.enqueue(13983) number_queue.enqueue(10080) number_queue.enqueue(7113) number_queue.enqueue(2520) number_queue.enqueue(2500) check_numbers(number_queue)
def __init__(self): self.queue = Queue.Queue()
def Append(self, v): Queue.Append(self, v) self.Animator.SetVertexColor(v, self.ColorOn)
def setUp(self): self.emptyqueue = Queue() self.queue = Queue() for letter in "abcdefghijklmnopqrstuvwxyz": self.queue.enqueue(letter)
class QueueTestCase(unittest.TestCase): def setUp(self): self.emptyqueue = Queue() self.queue = Queue() for letter in "abcdefghijklmnopqrstuvwxyz": self.queue.enqueue(letter) def test_len(self): self.assertEqual(len(self.queue), 26, "Queue length not 26") self.assertEqual(len(self.emptyqueue), 0, "Empty queue length not 0") self.queue.enqueue("aa") self.assertEqual(len(self.queue), 27, "Queue length not 27 after enqueue") self.queue.dequeue() self.assertEqual(len(self.queue), 26, "Queue length not 26 after dequeue") self.queue.make_empty() self.assertEqual(len(self.queue), 0, "Queue length not 0 after make_empty") def test_str(self): letters = "abcdefghijklmnopqrstuvwxyz" string = str([letter for letter in letters]) self.assertEqual(str(self.queue), string, "Queue string not equal") self.assertEqual(str(self.emptyqueue), str([]), "Empty queue string not equal") def test_bool(self): self.assertTrue(self.queue, "Queue unexpectedly false") self.assertFalse(self.emptyqueue, "Empty queue unexpectedly true") def test_enqueue(self): item = "aa" self.assertNotIn(item, self.queue._data) self.queue.enqueue(item) self.assertIn(item, self.queue._data) self.assertEqual(item, self.queue._data[-1]) def test_dequeue(self): self.assertEqual(self.queue.dequeue(), "a") self.assertNotIn("a", self.queue._data) with self.assertRaises(IndexError): self.emptyqueue.dequeue() def test_peek(self): self.assertEqual(self.queue.peek(), "a") self.assertIn("a", self.queue._data) with self.assertRaises(IndexError): self.emptyqueue.peek() def test_make_empty(self): self.assertTrue(self.queue) self.queue.make_empty() self.assertEqual(self.queue._data, [])
def load(): global queue with open("queue.json", 'r') as f: data = json.load(f) f.close() queue = Queue(mode="FIFO", current_queue=data)
import json, os from DataStructures import Queue from sms import send # there queue has to be declared globally (outside any other function) # that way all methods have access to it queue1 = Queue(mode="FIFO", current_queue=[]) #first in first out def print_queue(): # you must print on the console the entire queue list print("Printing the entire list...") print(queue1.get_queue()) def add(): phone_number = input( "Hello, Please enter the best phone number to reach you at.") queue1.enqueue(phone_number) print( f'Thank You, phone number {phone_number} has been added to the waiting list.' ) print_queue() def dequeue(): phone_number = queue1.dequeue() # send(body=f'The {phone_number} has been removed from the waiting list', to={phone_number}) #print(f"Your phone number {phone_number} has been removed and notified.")