-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.py
More file actions
43 lines (37 loc) · 977 Bytes
/
Stack.py
File metadata and controls
43 lines (37 loc) · 977 Bytes
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
39
40
41
42
43
L = []
while True:
c = int(input('''
1 Push Elements
2 Pop Elements
3 Last Element
4 Display Stack
5 Exit
6 pop through index\n'''))
if c == 1:
n = input("Enter The Value")
L.append(n)
print(L)
elif c == 2:
if len(L) == 0:
print("Empty Stack")
else:
p = L.pop()
print(p)
print(L)
elif c == 3:
if len(L) == 0:
print("Empty Stack")
else:
print("Last Stack Value", L[-1])
elif c == 4:
print("Display Stack", L)
elif c == 5:
break
elif c == 6:
print("before",len(L))
if len(L) == 0:
print("Empty Stack")
else:
print("after",len(L))
d=L.pop(int(input("index no. : ")))
print(d)