Q. Write an interactive menu-driven program implementing Stack using list. The list is storing numeric data.
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 = int(input("Enter the data :- ")) stack.append(data) elif user == "delete" : if stack == [ ]: print("Under-flow") else : stack.pop() else : break print("Now our stack = ", stack)
Answer :-
>>>
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 data :- 54
Now our stack = [54]
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 data :- 54
Now our stack = [54]
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 data :- 3598
Now our stack = [54, 3598]
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 = [54]
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 data :- 887
Now our stack = [54, 887]
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
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )