Write a Python program to implement a stack using a list data-structure.

def push(top,number,stack):
   top=top+1
   stack.append(number)
   return top
 
def pop(top,stack):
   if (top==-1):
     print('stack empty')
     return top
   print('item poped is ',stack[top])
   stack.remove(stack[top])
   top=top-1
   return top
  
# main program /starting point
stack=[]
top=-1
choice=0
while(choice!=4):
    print('press 1:push 2:pop 3:show list 4:exit')
    choice=int(input())
    if(choice==1):
       number=int(input('enter the number to push'))
       top=push(top,number,stack)
    elif(choice==2):
       top=pop(top,stack)
    elif(choice==3):
       print('now the stack is')
       size=len(stack)
       print('top')
       print('↓')
       i=size
       if size>0:
         while(i>0):
             print(stack[i-1])
             i=i-1
       else:
             print('empty')
 
Explanation: In this program we are declaring a empty list named stack. we are using a index pointer integer variable named top and initializing it with value -1. choice variable for capturing user choice from keyboard. inside while loop we are executing statements according to choice of user. choice 1 is to push number in the list, here program will call push defined function where top is incremented by 1.
 
append function of list is used to add the number to the list. append adds a element at the last of the list. now top variable points to latest added element. choice 2 is to remove top element from stack, we call it poping of element. in stack structure LIFO(last in first out) system works. remove function of list is used for this purpose in pop function definition.
 
top variable now points to previous index position in the list. that is why we used top=top-1. we are also checking if top is having value -1, it means stack list is empty.choice 3 is used to show items in stack. we are taking number of elements in size variable and checking if elements are there , the print those with while loop. other wise print empty message.