Answer to Question #323926 in Python for kr44

Question #323926

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


1
Expert's answer
2022-04-05T13:18:27-0400
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  
    

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS