Ram has a list containing 10 integers . you need to help him create a program with separate user defined function to perform the following operation based on this list
· Push the even number into stack
· Pop the content of the stack
· Display content of the stack
stack = [i for i in range(10)]
while 1:
print("1. Push element into stack\n2. Pop element from stack\n3. Print stack\n4. Exit")
inp = input("> ")
if(inp == '1'):
try:
stack.insert(0, int(input(">> ")))
except Exception:
print("Try again!")
if(inp == '2'):
stack.pop(0)
if(inp == '3'):
print(stack)
if(inp == '4'):
break
Comments
Leave a comment