Answer to Question #260342 in Python for Raju

Question #260342

IPL Match Details



Write a program that reads all the match outcomes and summarizes the information of all the matches.


Points are given to the terms based on the outcome of the match.


A win earns a team 3 points.A draw earns 1.A loss earns 0.


The following information is expected:


MP:Matches Played


W:Matches Won


D:Matches Drawn(Tied)


L:Matches Lost


P:Points



The team information should be displayed in descending order of points.



Sample input 1


6


CSK;RR;loss


RR;DD;draw


MI;KKR;win


KKR;RR;loss


CSK;DD;draw


MI;DD; draw



Sample output 1


Team: RR, Matches Played: 3, Won: 2, Lost: 0, Draw: 1, Points: 7


Team: MI, Matches Played: 2, Won: 1, Lost: 0, Draw: 1, Points: 4


Team: DD, Matches Played: 3, Won: 0, Lost: 0, Draw: 3, Points: 3


Team: CSK, Matches Played: 2, Won: 0, Lost: 1, Draw: 1, Points: 1


Team: KKR, Matches Played: 2, Won: 0, Lost: 2, Draw: 0, Points: 0

1
Expert's answer
2021-11-04T00:21:52-0400
def main():
 N=int(input(""))
 if N>=0 and N<=100:
 teamsData = {}
 for i in range(N):
     values = input().split(';')
     firstTeam = values[0].strip()
     secondTeam = values[1].strip()
     matchResult = values[2].strip()
 
 if(firstTeam not in teamsData):
 
 teamsData[firstTeam]=[0,0,0,0,0]
 if(secondTeam not in teamsData):
     teamsData[secondTeam]=[0,0,0,0,0] 
 if(firstTeam in teamsData and secondTeam in teamsData):
     teamsData[firstTeam][0]+=1
     teamsData[secondTeam][0]+=1

 if matchResult == 'win':
     teamsData[firstTeam][1]+=1
     teamsData[secondTeam][2]+=1
 elif matchResult == 'loss':
     teamsData[firstTeam][2]+=1
     teamsData[secondTeam][1]+=1
 elif matchResult == 'draw':
     teamsData[firstTeam][3]+=1
     teamsData[secondTeam][3]+=1

 for t in teamsData:
     teamsData[t][4]=teamsData[t][1]*3+teamsData[t][3]
 
 teamsData=(sorted(teamsData.items(), key = lambda points: points[1][4],reverse=True))
 for t in teamsData:
     ouput = f'Team: {t[0]}, Matches Played: {t[1][0]}, Won: {t[1][1]}, Lost: {t[1][2]}, Draw: {t[1][3]}, Points: {t[1][4]}'
     print(ouput)
 
 
main() 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog