Q. Write Addscore(Game) and Delscore(Game) methods in Python to add new Score in the list of score in a game and remove a score from a list of score of a game considering these methods to act as PUSH and POP operation of data structure Stack.
Answer =
def Addscore(Game) : stack.append(Game) def Delscore() : stack.pop() 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" : score = float(input("Enter the new score :- ")) Addscore(score) elif user == "delete" : if stack == [ ]: print("UnderFlow") else : Delscore() 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 new score :- 58
Now our stack = [58.0]
1. For insert data Enter 'insert'
2. For delete data enter 'delete'
3. For Exit Enter 'exit'
Enter your choice:- insert
Enter the new score :- 58
Now our stack = [58.0]
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 new score :- 647.26
Now our stack = [58.0, 647.26]
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 new score :- 100.1
Now our stack = [58.0, 647.26, 100.1]
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 = [58.0, 647.26]
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 : )