-
Notifications
You must be signed in to change notification settings - Fork 0
/
12stack_push_pop.py
85 lines (36 loc) · 969 Bytes
/
12stack_push_pop.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# stack, loads the data from the end point and read it from the end only.
def push_stack():
r = int(input("Enter yur roll no.= "))
name=input("Enter your name = ")
a=(r,name)
s.append(a)
def pop_stack():
if (s==[]):
print("stack empty")
else:
r,name=s.pop(0)
print("Deleted Roll Number and Name is :",r,name)
def display_stack():
if (s==[]):
print("stack empty")
else:
for i in range(len(s)-1,-1,-1):
print(s[i])
#main program
s = []
ch = 'y'
while ch[0]=='y' or ch[0]=='Y':
print("1. Push")
print("2. Pop")
print("3. Display")
ch=int(input("Enter your choice"))
if ch== 1 :
push_stack()
elif(ch==2):
pop_stack()
elif(ch==3) :
display_stack()
else:
print("!!!!Wrong Input!!!!")
ch = input("Do you want to proceed 'y or 'n ")
print('Program Exit')