Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
20 views2 pages

Stack Push

This document contains a Python program that implements a stack using a list. It provides functions to push elements onto the stack, pop elements from it, peek at the top element, and display the current stack. The program runs in a loop, allowing the user to perform these operations until they choose to exit.

Uploaded by

taritsaha09
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)
20 views2 pages

Stack Push

This document contains a Python program that implements a stack using a list. It provides functions to push elements onto the stack, pop elements from it, peek at the top element, and display the current stack. The program runs in a loop, allowing the user to perform these operations until they choose to exit.

Uploaded by

taritsaha09
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
You are on page 1/ 2

#stack Push_Pop program using list

s=[]
def push():
a=int(input("Enter Element: "))
s.append(a)
display()

def display():
if s==[]:
print("Stack Empty..")
else:
length=len(s)
for i in range(length-1,-1,-1):
print(s[i])
def pop():
if s==[]:
print("Stack Empty..")
else:
b=s.pop()
print("\nDEleted Item is...",b)
def peek():
if s==[]:
print("Stack Empty..")
else:
length=len(s)
top=length-1
print(s[top])
while True:
print("1.PUSH\n")
print("2.POP\n")
print("3.PEEK\n")
print("4.DISPLAY\n")
print("5.EXIT\n")
ch=int(input("\nEnter your Choice : "))
if ch==1:
push()
elif ch==2:
pop()
elif ch==3:
peek()
elif ch==4:
display()
elif ch==5:
break
else:
print("wrong input :")

z=input("Do u want to continue (Y/N) : ")


if z=='n' or z=='N':
break

You might also like