Q. Write an interactive menu-driven program to implement Stack using list. The list contains the names of students.


Answer :-

stack = [ ]
while True :
    print()
    print("Enter your choice as per given -")
    print("1 = For insert data Enter insert ")
    print("2 = For delete data enter delete ")
    print("3 = For Exit  enter exit ")
    print()
    user = input("Enter your choice :- ")
    if user == "insert" :
        data = input("Enter the name of student :- ")
        stack.append(data)
    elif user == "delete" :
        if stack == [ ]:
            print("UnderFlow")
        else :
            stack.pop()
    else :
        break
    print("Now our stack = ",stack)

Output :-

Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choice :- insert
Enter the name of student :- Path
Now our stack =  ['Path']

Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choice :- insert
Enter the name of student :- Computer
Now our stack =  ['Path', 'Computer']

Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choice :- delete
Now our stack =  ['Path']

Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choice :- insert
Enter the name of student :- Walla
Now our stack =  ['Path', 'Walla']

Enter your choice as per given -
1 = For insert data Enter insert
2 = For delete data enter delete
3 = For Exit  enter exit

Enter your choice :- exit

>>>

4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post