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

Stack Operations in Python Program

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)
10 views2 pages

Stack Operations in Python Program

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

#stack Push_Pop program using list

s=[]
def push():
a=int(input("Enter Element: "))
[Link](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=[Link]()
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("[Link]\n")
print("[Link]\n")
print("[Link]\n")
print("[Link]\n")
print("[Link]\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