# Stack using List
stack = []
# Function to check if stack is empty
def isEmpty():
if len(stack) == 0:
return True
return False
# Function to push an element
def push(item):
[Link](item)
print(item, "pushed into stack")
# Function to pop an element
def pop():
if isEmpty():
print("Stack is Empty")
else:
print([Link](), "popped from stack")
# Function to display stack
def display():
if isEmpty():
print("Stack is Empty")
else:
print("Stack elements are:")
for i in range(len(stack) - 1, -1, -1):
print(stack[i])
# Main Program
while True:
print("\n----- STACK MENU -----")
print("1. Push")
print("2. Pop")
print("3. Check Empty")
print("4. Display")
print("5. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
item = int(input("Enter element to push: "))
push(item)
elif choice == 2:
pop()
elif choice == 3:
if isEmpty():
print("Stack is Empty")
else:
print("Stack is Not Empty")
elif choice == 4:
display()
elif choice == 5:
print("Program Ended")
break
else:
print("Invalid Choice")
----- STACK MENU -----
1. Push
2. Pop
3. Check Empty
4. Display
5. Exit
Enter your choice: 1
Enter element to push: 10
10 pushed into stack
Enter your choice: 1
Enter element to push: 20
20 pushed into stack
Enter your choice: 4
Stack elements are:
20
10
Enter your choice: 2
20 popped from stack
Enter your choice: 3
Stack is Not Empty