Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need some help to fixing Python bugs: For the second picture, I suppose to get 17 for the test, but my codes got 3 instead,

Need some help to fixing Python bugs:

image text in transcribedimage text in transcribed

For the second picture, I suppose to get 17 for the test, but my codes got 3 instead, please fix it for me! Thank you

is an element and n is the Here's the 'smart' implementation of a counting queue that we saw during class. It stores pairs (2,n), where count of the number of occurrences of I. [] class CountingQueue(object): def __init_(self): self.queue = ] def _repr_(self): return repr(self.queue) def add(self, x, count=1): # If the element is the same as the last element, we simply # increment the count. This assumes we can test equality of elements. if len(self.queue) > @: xx, CC = self.queue[-1] if xx == X self.queue[-1) = (xx, CC + count) else: self.queue.append((x, count)) else: self.queue = [(x, count)] def get(self): if len(self.queue) == @: return None X, C = self.queue[@] if C 1: self.queue.pop() return x else: self.queue[@] = (x, C-1) return x def isempty(self): # Since the count of an element is never #whether the queue is empty. , we can just check For this exercise, you will implement the _len__ method for the CountingQueue class defined above. This should require no more than 4 lines of code def countingqueue_len(self): return len(self.queue) # This is a way to add a method to a class once the class # has already been defined. CountingQueue. _len__ = countingqueue_len Hux Tests for ' _len__ fron nose.tools import assert_equal 4 = CountingQueue () for i in range(10): 4.add('a') 9.add('5') for 1 in range(3): 4.add('c', count=2) assert_equal(len(9), 17) AssertionError Traceback (most recent call last) in () 8 for i in range(3): 9 4 .add('c', count=2) ---> 10 assert_equal(len(9), 17) 1 frames - /usr/lib/python3.6/unittest/case.py in _baseAssertEqual(self, first, second, msg) 820 standardMsg = 's != '%_common_shorten_repr(first, second) msg = self._formatMessage(msg, standardMsg) --> 822 raise self.failureException(msg) 823 824 def assertEqual(self, first, second, msg=None): AssertionError: 3 != 17

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions