Question: Code required Extending from the Stack class: class Stack: def __init__(self): self.lst = [] def push(self, item): self.lst.append(item) def pop(self): if self.is_empty(): raise IndexError('The stack

Code required

Extending from the Stack class:

class Stack: def __init__(self): self.lst = []

def push(self, item): self.lst.append(item)

def pop(self): if self.is_empty(): raise IndexError('The stack is empty!') return self.lst.pop()

def peek(self): if self.is_empty(): raise IndexError('The stack is empty!') return self.lst[-1]

def size(self): return len(self.lst)

def is_empty(self): return self.size() == 0Code required Extending from the Stack class: class Stack: def __init__(self): self.lst

Extend the Stack class by adding the method_ str (self). It is used to print out all items in the stacks. Note, this method does not remove any elements from the stack. You should include the entire Stack class definition. For example 2 Extend the Stack class by addling the method push Jistiself,my. list) that push all elements from the ist into the stack one by one Test Result You should include the entire Stack class definition in your answer to this question. my stack-Stack() Stack my stack-push('a') my_stack.push( 'b) my_stack.push('c) print (my_stack) [a, b, c] For example: Test Result my_stack Stack) Stack: [] my_stack.push'a) my stack-push('b') my_stack.pop) my_stack.pop) print (my_stack) my-stack Stack() rylist-[4,5,6] my_stack.push_list(mylist) print (my_stack.peek)) print(my_stack.size)) tend the Stack class by addng the method multi pop(self, num) that pops "nu" of elements from the stack or until the stack s empty there is ot enough iems inside the stack. This method should not pop out any tem and reurn None. It returns a list of elements if the items are popped out You should include the entise Stack class defnition in your answer to this question For example: my_stack Stack() my_stack.push_list(['a']) print(my stack.peek()) print(my_stack.size()) Test Result y stack-Stack) ny.stack.pushc 'a) aystack-push('b') mystack.push(') print(ay stack.peek)) print(ey stack.multi pop(3)) print(ay stack,size)) y stack Stack) ay stack.push'd') my stack.push'e') ay stack-push print(ey stack.multi pop(5)) print(ay stack.size)) print(ey stack.pesk))

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!