Question: The following code block is a _ _ str _ _ ( ) method for a Stack class used to implement a stack data structure

The following code block is a __str__() method for a Stack class used to implement a stack data structure in Python. What code belongs in the blank if the desired behavior for this method is to return a string that can be used to display the elements in a stack from top to bottom?
def __str__(self):
string = "Top to bottom: "
traverser = self.top
_____
return string
a.
while traverser == None:
string += str(traverser.data)+""
traverser = traverser.next
b.
while traverser != None:
string += str(traverser.data)+""
traverser = traverser.next
c.
print(self.data)
d.
for i in traverser:
string += str(traverser.data)+""
traverser = traverser.next

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 Programming Questions!