-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.py
39 lines (32 loc) · 909 Bytes
/
stack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class stack:
def __init__(self):
self.items = []
def push(self,value):
return self.items.append(value)
def pop(self):
return self.items.pop()
def is_empty(self):
if (self.items == []):
return True
return False
def peek(self):
if not self.is_empty():
return self.items[-1]
def display(self):
print(self.items)
s = stack()
print("1: push \n 2:pop\n 3:is_empty\n 4:peek\n, 5: display\n ")
while (True):
choice = int(input("Enter your choice:\n"))
if choice == 1:
item = input("Enter a character:\n")
s.push(item)
elif (choice ==2):
s.pop()
elif( choice == 3):
print( s.is_empty())
elif(choice == 4):
print(s.peek())
elif (choice == 5):
s.display()
# n = int(input("Enter the number of element you wish for your stack:\n"))