Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In python add a method to this code provided that reverses the contents of the s

ID: 3858844 • Letter: I

Question

In python add a method to this code provided that reverses the contents of the stack. Thanks! class Stackt: def__init__(self): #creating an empty list self.list=[] def push (self, item): #append to list self.list.append(item) def pop(self): #dont mention what you want to pop return self.list.pop() def peek(self): return self.list[len(self.list)-1] def size(size): #return len of list return len(self.list) def is__empty (self): if len(self.list)--0: return True else: return False s1=Stack() s1.push(5) s1.push(6) s1.push(7) class Stack: def__init__(self): #creating an empty list self.list=[] def push(self, item): #append to list self.list.append(item) def pop(self): #dont mention what you want to pop return self.list.pop() def peek(self): #return self.list[len(self.list)-1] def size(self): #return len of list return len(self.list) def is__empty(self): if len(se1f.list)==0: return True else: return False s1=Stack() s1.push(5) s1.push(6) s1.push(7) print(s1.peek()) print(s1.size())

Explanation / Answer

class Stack:

def __init__(self):

#creating an empty list

self.list=[]

def push(self, item):

#append to list

self.list.append(item)

def pop(self):

#don't mention what you want to pop

return self.list(len(self.list) - 1)

def size(self, size):

#return len of list

return len(self.list)

def is_empty(self):

if len(self.list) == 0:

return True

else:

return False

def reverse(self):

temp = self.list

while temp.size() > 0:

self.list.push(temp.pop())

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote