Q. Repeatedly ask the user to enter a team name and how many games the team has won and how many they lost. Store this information in a dictionary where the keys are the team names and the values are a list of the form [wins, losses].

(i) using the dictionary created above, allow the user to enter a team name and print out the team’s winning percentage.
(ii) using dictionary create a list whose entries are the number of wins for each team.
(iii) using the dictionary, create a list of all those teams that have winning records.


You can understand by Watching video :-



Answer :-

dic ={}
lstwin = []
lstrec = []
while True :
    name = input ("Enter the name of team (enter q for quit)= ")
    if name == "Q" or name == "q" :
        print()
        break
    else :
        win = int (input("Enter the no.of win match = "))
        loss = int(input("Enter the no.of loss match = "))
        print()
        dic [ name ] = [ win , loss ]
        lstwin += [ win ]
        if win > 0 :
            lstrec += [ name ]

nam = input ("Enter the name of team For Winning = ")
print ("Winning percentage = ",dic [ nam ][0] *100 / (dic [nam ][0] + dic[nam ][1] ))
print()
print("Winning list of all team = ",lstwin)
print("Team who has winning records are ",lstrec)

Output :-

Enter the name of team (enter q for quit)= Path
Enter the no.of win match = 9
Enter the no.of loss match = 1

Enter the name of team (enter q for quit)= Walla
Enter the no.of win match = 5
Enter the no.of loss match = 5

Enter the name of team (enter q for quit)= Portal
Enter the no.of win match = 0
Enter the no.of loss match = 10

Enter the name of team (enter q for quit)= Express
Enter the no.of win match = 8
Enter the no.of loss match = 2

Enter the name of team (enter q for quit)= q

Enter the name of team For Winning = Path
Winning percentage =  90.0

Winning list of all team =  [9, 5, 0, 8]
Team who has winning records are  ['Path', 'Walla', 'Express']

>>> 


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