Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Dec 31, 2020
Embed
What would you like to do?
class Stack:
def __init__(self):
self.theItems = list()
def isEmpty(self):
return len(self) == 0
def __len__(self):
return len(self.theItems)
def pop(self):
assert not self.isEmpty()
return self.theItems.pop()
def push(self, item):
self.theItems.append(item)
PROMPT = "Enter an int value : "
myStack = Stack()
value = int(input(PROMPT))
while value >= 0:
myStack.push(value)
value = int(input(PROMPT))
while not myStack.isEmpty():
value = myStack.pop()
print(value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment