-
-
Save amankharwal/f88a9396ae086338d71104fc973813dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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