0% found this document useful (0 votes)
2 views4 pages

Stack Operations in Python Code Examples

Uploaded by

veduomer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Stack Operations in Python Code Examples

Uploaded by

veduomer
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

mystack=[]
def push(name):
[Link](name)
print(mystack)

def pop():
if mystack==[]:
print("stack is empty")
else:
print([Link]())
2.
mystack=[]
def push(name):
if len(mystack)<2:
[Link](name)
else:
print(‘Stack is full’)
3.
mystack=[]
def add(bookname):
[Link](bookname)
print(mystack)

def delete():
if mystack==[]:
print("stack is empty")
else:
print([Link]())

4.
mystack=[]
def push(name):
[Link](name)
print(mystack)

def pop():
if mystack==[]:
print("stack is empty")
else:
print([Link]())

def display():
if mystack==[]:
print("stack is empty")
else:
for i in mystack[::-1]:
print(i)
5.
R={"OM":76, "JAI":45, "BOB":89,"ALI":65, "ANU":90, "TOM":82}
st=[] #stack in which we will push the required data
def push():
for i in R:
if R[i]>75:
[Link](i)
print(st)

def pop():
for i in range(len(st)):
print([Link](),end=" ")

push()
pop()

6.
N=[12,13,34,56,21,79,98,22,35,38]
st=[]
def push():
for i in N:
if i%2==0:
[Link](i)
print(st)

def pop():
for i in range(len(st)):
print([Link](),end=" ")

push()
pop()

7.

L=[10,12,15,16,17,18,20,21,25]
st=[]
def push(L):
for i in L:
if i%5==0:
[Link](i)
print(st)

push(L)
8.
L=['Ansh','Vipin','Ishan','Devesh','Om','Upashna']

st=[]
def push():
for i in L:
if i[0] in "AEIOU":
[Link](i)
print(st)

push()

9.
result=[]
def push():
while True:
c=int(input("enter code:"))
n=input("enter name:")
p=int(input("enter price:"))
d=[c,n,p]
[Link](d)
y=input("want more data")
if y!="y":
break
print(result)

push()

10.
Dic={"Manager":108, "Clerk":115, "Analyst":112, "Operator":105, "HR":127}
stack=[]
def push():
for i in Dic:
if Dic[i]<110:
[Link](i)
print(stack)

def pop():
for i in range(len(stack)):
print([Link](),end=" ")
11.
status=[]
def push():
while True:
mob=int(input("enter mobile no:"))
name=input("enter name:")
lst=[mob,name]
[Link](lst)
y=input("want more data")
if y!="y":
break
print(status)

push()
12.
hostel=[]
def push():
hno=int(input("enter Hostal no:"))
tstud=int(input("enter no of student:"))
troom=int(input("enter no of room:"))
lst=[hno,tstud,troom]
[Link](lst)
print(hostel)

def pop():
if hostel==[]:
print("stack is empty")
else:
print([Link]())

You might also like