def TestFactory(): # Create a list of colors to compare with user input, if the color is not in # the list, cancel the order color_choice = ["red", "white", "blue"] customer_orders = MyQueue() # Intitalize a boolean b = True while b : print("Welcome to the Waskelly Wabbit Wiget Works automated odering system!") print("") name = input("\t Please input customer name (or exit): ") # If the User enters exit, break out of the loop if name == "exit": break color = input("\t Please select desired widget color (red, white, blue): ") # If the color isnt one of the choices given, continue if color_choice.count(color) == 0: print("Sorry, that's not a color we offer. Order cancelled. \n") continue quantity = input("\t Excellent choice. How many %s widgets do you want? "%(color)) # If the number given is not a valid positive integer, continue if not quantity.isdigit(): print("Bad quantity. Order cancelled \n") continue print("Order confirmed! Please shop with us again. \n") customer_orders.enqueue(Order(name, color, quantity)) print("") print ("Now processing orders:") # While the Queue is full while not customer_orders.isEmpty(): # Use the getter or accessors from the Order class processed_Order = customer_orders.dequeue() order_Num = processed_Order.getOrderNum() order_Name = processed_Order.getCustomerName() order_Color = processed_Order.getCustomerColor() order_Quantity = processed_Order.getCustomerQuantity() # Print the orders and their values out print (" Order Shipped: \t Order %d: customer %s requests %s %s widgets." \ % (order_Num, order_Name, order_Quantity,order_Color)) # Since the while loop broke, the Queue is empty print("Queue empty.")
def squreAllHouse(squre): if queuesDict.has_key(squre): queue = queuesDict[squre] else: queue = MyQueue(40) for house in get_houselist(squre): print house houseObj = getHouse(house, squreDict[squre]) print houseObj.title if houseObj.url not in queue: queue.enqueue(houseObj.url) save(houseObj) if (queue.isfull()): queue.dequeue() queuesDict[squre] = queue
def breadth_first_order(tnode): explore = MyQueue.create() MyQueue.enqueue(explore, tnode) while MyQueue.size(explore) > 0: current = MyQueue.dequeue(explore) print(tn.get_data(current), end=" ") left = tn.get_left(current) if left is not None: MyQueue.enqueue(explore, left) right = tn.get_right(current) if right is not None: MyQueue.enqueue(explore, right)
def main(): i = 0 y= MyQueue() x = Order() while True: end = False print ("Welcome to the Waskelly Wabbit Widget Works automated ordering system!") print ('') name = input ("Please input customer name (or exit) ") if (name == "exit"): print ('') print ("Now processing orders: ") break else: x.name=name color = input ("Please select desired widget color (red, white, blue) ") ## Ask the user for a color color=color.lower() if (color == "red"): x.color=color elif (color == "white"): x.color=color elif (color == "blue"): x.color=color else: end = True if end == True: ##If the color is invalid, start the ordering process over print ("Sorry, that's not a color we offer. Order cancelled.") print ('') continue quan = input (("Excellent choice, how many %s widgets do you want? ") % (x.color)) if (quan.isdigit()): #Ask for the quantity and make sure that the input is valid x.quantity=quan print ("Order confirmed! Please shop with us again.") print ('') else: end = True if end == True: ## If the input is invalid, restart the ordering process print ("Bad quantity. Order cancelled") print ('') continue i = i + 1 ##Keep track of the number of orders x.number= i ## Add the successful order to the queue toenq=(("Order %s: customer %s requests %s %s widgets") % (x.number, x.name, x.quantity, x.color)) y.enqueue(toenq) while not (y.isEmpty()): print (("Order shipped: %s") % (y.dequeue())) else: print ("Queue empty")
def testQueue(): q = MyQueue(1) # Initalisierungs Checks assert q.max == 1, "Maximale Größe passt nicht" assert q.size == 0, "Aktuelle Größe passt nicht" is_empty = q.empty() assert is_empty, "Nach Initalisierung sollte die Schlange noch leer sein" is_full = q.full() assert is_full == False, "Schlange ist nach Initalisierung nicht voll" assert q.size == 0, "Größe passt nicht" succeeded = q.enqueue(1) assert succeeded, "Erfolgreich eingefügt" check(q) is_full = q.full() assert is_full, "Schlange ist voll" value = q.dequeue() assert value == 1, "Wert sollte 1 sein" check(q) is_empty = q.empty() assert q.empty(), "Schlange ist wieder leer" check(q) succeeded = q.enqueue(-42) assert succeeded, "Erfolgreich eingefügt" check(q) value = q.dequeue() assert value == -42, "Wert sollte 1 sein" check(q) value = q.dequeue() assert value == None, "Schlange war schon leer" check(q) is_empty = q.empty() assert q.empty(), "Schlange ist wieder leer" check(q) succeeded = q.enqueue(1) assert succeeded, "Erfolgreich eingefügt" succeeded = q.enqueue(2) assert succeeded == False, "Konnte Elelement nicht einfügen" check(q) value = q.dequeue() assert value == 1, "Hätte nicht überschreiben dürfen" check(q) is_empty = q.empty() assert is_empty, "Sollte wieder leer sein" succeeded = q.enqueue(2**31 - 1) assert succeeded, "Einfügen geklappt" value = q.dequeue() assert value == (2**31 - 1), "Zu große Zahl" q = MyQueue(3000) for x in range(2000): #print(x) value = x succeeded = q.enqueue(value) assert succeeded, "Einfügen muss klappen" assert not q.empty(), "Darf nicht leer sein" assert not q.full(), "Darf nicht voll sein" check(q) #print() for x in range(2000): value = q.dequeue() #print(value) iter = x assert (iter == value), "Wert passt nicht" assert not q.full(), "Darf nicht voll sein" check(q) for x in range(2000): #print(x) value = x * -1 succeeded = q.enqueue(value) assert succeeded, "Einfügen muss klappen" assert not q.empty(), "Darf nicht leer sein" assert not q.full(), "Darf nicht voll sein" check(q) #print() for x in range(2000): value = q.dequeue() #print(value) iter = x * -1 assert (iter == value), "Wert passt nicht" assert not q.full(), "Darf nicht voll sein" check(q)
def TestFactory(): """An interactive widget ordering system to handle orders of widgets containing data about customer name, widget color and quantity.""" #Order Variable Reset name = "" color = "" num = "" #Order queue queue = MyQueue() #Keep program running until exit while True: #welcome message print("\nWelcome to the Waskelly Wabbit Widget Works automated ordering system!") #user inputs name (or type 'exit') name = input("\n\tPlease input customer name (or exit): ") #check for actual input, if none, re-ask if name == "": continue #check lower case name for the word 'exit' if name.lower() == "exit": break #user inputs order color color = input("\tPlease select desired widget color (red, white, blue): ").lower() #if not defined color, cancel order if not color in ["red", "white", "blue"]: print("\t\tSorry, %s not a color we offer. Order cancelled." %color) continue #iser inputs order quantity num = input("\tExcellent choice. How many %s widgets do you want? " %color) #if value not a positive whole number, cancel order if not num.isnumeric(): print("\t\tBad quantity. Order cancelled.") continue #if made this far, all values are valid, create order newOrder = Order(name, color, num) #add new order to the order queue queue.enqueue(newOrder) #order confimation message #on exit process orders print("\nNow processing orders:\n") #iterate over order queue, dequeue orders for order in range(len(queue)): print(" Order shipped:\t", queue.dequeue()) #all orders processed message print("\nQueue empty")