Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created December 31, 2020 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/f88a9396ae086338d71104fc973813dc to your computer and use it in GitHub Desktop.
Save amankharwal/f88a9396ae086338d71104fc973813dc to your computer and use it in GitHub Desktop.
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