Write a menu based program to add delete and display the record of players by using list as Stack in python. Record of a player contains: Player code, score and Rank.

Program to add delete and display the record of players by using list as Stack in python

 

player = []
ch = 'y'
def push(player):
    pcode = int(input('Enter Player Code\t:\t'))
    pscore = int(input('Enter Player Score\t:\t'))
    prank = int(input('Enter Player Rank\t:\t'))
    temp = [pcode, pscore, prank]
    player.append(temp)

def pop(player):
    if player == []:
        print ('No Record')
    print ('Deleted Record is :', player.pop())

def displaydata(player):
    L = len(player)
    print ('player Code\tPlayer Score\tPlayer Rank')
    for i in range(L-1,-1,-1):
        print(player[i][0],"\t\t",player[i][1],"\t\t", player[i][2])

while ch == 'y' or ch == 'Y':
    print ('1. Add Record\n')
    print ('2. Delete Record\n')
    print ('3. Display Record\n')
    print ('4. Exit')
    op = int(input('Enter the Choice\t:\t'))
    if op == 1:
        push(player)
    elif op == 2:
        pop(player)
    elif op == 3:
        displaydata(player)
    elif op == 4:
        break
ch = input('Do you want to enter more(Y/N)')

 

 

 

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved
error: Content is protected !!