05 01 2024 (Stack)
05 01 2024 (Stack)
For example:
If the lists of customer details are:
[“Gurdas”, “99999999999”,”Goa”]
[“Julee”, “8888888888”,”Mumbai”] [“Murugan”,”77777777777”,”Cochin”]
[“Ashmit”, “1010101010”,”Goa”]
stack=[]
def push(stack,item):
# if len(stack)==5:
# print("stack is overflow")
# else:
stack.append(item)
def pop():
if len(stack)==0:
print("Stack is Underflow")
else:
print(stack.pop()," Pop from stack")
def peek():
if len(stack)==0:
print("Stack is Empty")
else:
print(stack[-1]," <-- is at top")
def display():
if len(stack) == 0:
print("Stack is Empty")
else:
print(stack[-1], " <-- is at top")
for i in range(len(stack)-2,-1,-1):
print(stack[i])
l=[["Gurdas", "99999999999","Goa"],
STACK
["Julee", "8888888888","Mumbai"],
["Murugan","77777777777","Cochin"],
["Ashmit", "1010101010","Goa"]]
while True:
x=int(input("1.Push\n2.Pop\n3.Peek\n4.Display\n5.Exit\n
Enter You Choice 1- 5: "))
if x==1:
for i in l:
if i[-1]=="Goa":
a=[i[0],i[1]]
push(stack,a)
elif x==2:
pop()
elif x==3:
peek()
elif x==4:
display()
elif x==5:
break
The function should push the names of those items in the stack who have price greater
than 75. Also display the count of elements pushed into the stack.
For example:
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
stack=[]
def push(stack,item):
STACK
# if len(stack)==5:
# print("stack is overflow")
# else:
stack.append(item)
def pop():
if len(stack)==0:
print("Stack is Underflow")
else:
print(stack.pop()," Pop from stack")
def peek():
if len(stack)==0:
print("Stack is Empty")
else:
print(stack[-1]," <-- is at top")
def display():
if len(stack) == 0:
print("Stack is Empty")
else:
print(stack[-1], " <-- is at top")
for i in range(len(stack)-2,-1,-1):
print(stack[i])
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
while True:
x=int(input("1.Push\n2.Pop\n3.Peek\n4.Display\n5.Exit\n
Enter You Choice 1- 5: "))
if x==1:
for i in Ditem:
if Ditem[i]>75:
push(stack,i)
elif x==2:
pop()
elif x==3:
peek()
elif x==4:
display()
elif x==5:
break
STACK
OR
stack=[]
Ditem={"Pen":106,"Pencil":59,"Notebook":80,"Eraser":25}
def push():
for i in Ditem:
if Ditem[i] > 75:
stack.append(i)
def pop():
if len(stack)==0:
print("Stack is Underflow")
else:
print(stack.pop()," Pop from stack")
push()
print("Total Elements in Stack = ",len(stack))