Python Project

Python Program to perform Stack Operation in Python.

Class 12th CBSE STACK

Question

Python Program to perform Stack Operation in Python.

Solution :- 

l=[]
while True:
     c = int(input(”’
             1. Push Element
             2. Pop Element
             3. Peek Element
            4. Display Stack
            5. Exit
          ”’))
     if c ==1:
       n = input(“Enter the Value”)
       l.append(n)
        print(l)
     elif c==2:
       if len(l)==0:
       print(“Empty Stack”)
      else:
         p=l.pop()
         print(p)
         print(l)
        elif c==3:
            if len(l)==0:
               print(“Empty Stack”)
            else:
               print(“Last Stack value”,l[-1])
        elif c==4:
                 print(“Display Stack”,l)
       elif c==5:
                 break

Output :- 

 

TRY THIS CODE

 

Fun & Easy to follow
Works on all devices
Your own Pace
Super Affordable

Popular Videos

Play Video

UX for Teams

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer

Play Video

SEO & Instagram

Learn the basics and a bit beyond to improve your backend dev skills.

ava4.png
Chris Matthews

Designer