class Stack: """ Provides a rudimentary implementation of the stack data structure Attributes ---------- stack : (list of any) the underlying stack of objects Methods ------- is_empty(): (bool) returns whether the stack is empty add(item): (None) adds the item at the top of the stack remove(): (any) removes and returns the item from the top of the stack """ def __init__(self, initial_contents=[]): self.stack = initial_contents[:] def is_empty(self): """ returns whether the stack is empty :return: (bool) whether the stack is empty """ return self.stack == [] def add(self, item): """ adds the item at the top of the stack :param item: (any) the item to add at the top of the stack :return: (None) """ self.stack.append(item) def remove(self): """ removes and returns the item from the top of the stack :return: (any) the item from the top of the stack """ return self.stack.pop() def __str__(self): return "The stack contains: " + str(self.stack) def main(): s = Stack() print(s) s = Stack([1, 2, 3, 4]) print(s) s = Stack() s.add(1) s.add(10) s.add(2) print(s) s.remove() print(s) s.remove() print(s) s.remove() print(s) if __name__ == "__main__": main()