I am currently working on the "3.2.1.16 Queue aka FIFO: part 2" lab from edube:
Your task is to slightly extend the Queue class' capabilities. We want it to have a parameterless method that returns True if the queue is empty and False otherwise.
Complete the code we've provided in the editor. Run it to check whether it outputs a similar result to ours.
Below you can copy the code we used in the previous lab.
My code so far is as follows (I have copied the code for the Queue class and my task is now to work on the SuperQueue class):
class QueueError(IndexError):
pass
class Queue:
def __init__(self):
self.queue = []
def put(self,elem):
self.queue.insert(0,elem)
def get(self):
if len(self.queue) > 0:
elem = self.queue[-1]
del self.queue[-1]
return elem
else:
raise QueueError
class SuperQueue(Queue):
def __init__(self):
Queue()
def isempty(self):
if len(Queue.self.queue)==0:
return True
else:
return False
que = SuperQueue()
que.put(1)
que.put("dog")
que.put(False)
for i in range(4):
if not que.isempty():
print(que.get())
else:
print("Queue empty")
The crucial point is the if len(Queue.self.queue)==0. This does not work. What I want to do is to check if the length of the queue is zero. However, the queue is stored as an object in the other class. So how can I access it from the SuperQueue class?