Class 12th CBSE CS
Write a Program to perform Stack Operation.
Solution: –
def push(): n = int(input("Enter the number you want to add in Stack :- ")) stack.append(n) def pop(): if stack ==[]: print("Stack Underflow") else: print(stack.pop()) def peep(): if stack ==[]: print("Stack Underflow") else: print(stack[-1]) def display(): for i in range(len(stack)-1,-1,-1): print(stack[i]) stack=[] while True: n = int(input("""Enter your Choice :- Press 1 for Push operation. Press 2 for POP operation. Press 3 for Peep operatin. Press 4 for Display operation. Press 5 for Exit. """)) if n==1: push() elif n==2: pop() elif n==3: peep() elif n==4: display() else: break

Fun & Easy to follow

Works on all devices

Your own Pace

Super Affordable
Popular Videos

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

Chris Matthews
Designer

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

Chris Matthews
Designer