Programming Examples

Python program Repeatedly ask the user to enter a team name


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.

Solution

dic ={}
lstwin = []
lstrec = []
while True :
    name = input ("Enter the name of team (enter q for quit)=")
    if name == "Q" or name == "q" :
        break
    else :
        win = int (input("Enter the no.of win match ="))
        loss = int(input("Enter the no.of loss match ="))
        dic [ name ] = [ win , loss ]
        lstwin += [ win ]
        if win > 0 :
            lstrec += [ name ]     
nam = input ("Enter the name of team those you are entered =")
print ("Winning percentage =",dic [ nam ][0] *100 / (dic [nam ][0] + dic[nam ][1] ))
print("wining list of all team = ",lstwin)
print("team who has winning records are ",lstrec)
Output

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad