class Pila(object): "ejercicio 3-2" def __init__(self, *args): self.base = [] for arg in args: self.base.append(arg) def len(self): return len(self.base) def top(self): indice = self.len() - 1 return self.base[indice] def push(self, args): self.base.append(args) def pop(self): try: return self.base.pop() except IndexError: return "Fuera del indice/vacío" def is_empty(self): return (lambda x: True if x == 0 else False)(len(self.base)) miPila = Pila('uno', 'dos', 'tres', 'cuatro') print("Mi Pila1 :", miPila.base, '\n') print("Pila1 top() :", miPila.top(), '\n') print("Pila1 post - push('dieciseis') :", end='') miPila.push('dieciseis') print(miPila.base, '\n') print("Pila1 pop() :", miPila.pop(), '\n') print("Largo Pila1 :", miPila.len(), '\n') print("Esta la Pila1 vacía ? :", miPila.is_empty(), '\n') miPila2 = Pila() print("Esta vacía la Pila2 ? :", miPila2.is_empty(),'\n') print("Pila2 pop() : ", miPila2.pop())