Question: Answer in Python. Fill in where it says YOUR CODE HERE. Make sure it passes the tests provided _getitem [41] def counting_queue_getitem(self, n): # YOUR

Answer in Python. Fill in where it says YOUR CODE HERE. Make sure it passes the tests providedAnswer in Python. Fill in where it says YOUR CODE HERE. Makesure it passes the tests provided _getitem [41] def counting_queue_getitem(self, n): #YOUR CODE HERE CountingQueue. getitem = counting_queue_getitem [42] # 5 points: simple

_getitem [41] def counting_queue_getitem(self, n): # YOUR CODE HERE CountingQueue. getitem = counting_queue_getitem [42] # 5 points: simple tests. q = CountingQueue () q.add("cat", count=2) q.add("dog", count=3) q.add("bird", count=4) els = [q[i] for i in range(9)] assert els == ['cat'] * 2 + ['dog'] * 3+ ['bird'] * 4 # Let's do it again. els = [q[i] for i in range(9)] assert els l'cat'* 2tal dog'lub'bird' 1*4 # 5 points: you raise IndexError when accessing elements out of bounds. q = CountingQueue() q.add("cat", count=2) q.add("dog", count=3) # Raise IndexError when it's too high... try: q[5] assert False."Failed to raise IndexError" except IndexError: pass assert q[4] == "dog" try: q[5] assert False, "Failed to raise IndexError" except IndexError: pass # And also when it's too low. try: q[-10] assert False, "Failed to raise IndexError" except IndexError: pass # or too large : try: q[10] assert False, "Failed to raise IndexError" except IndexError: pass # And raise TypeError if you try to index with a non-integer. try: q["hello"] assert False, "Failed to raise TypeError" except TypeError: pass [ 43 ] # 5 points. Behaves the same as Queue. elements = range(3) for k in range(100): qo = Queue () q1 = CountingQueue ( ) for m in range (40): el = random.choice (elements) qo.add(el) ql.add(el) for i in range(m): assert qolih qi[i]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!