Answer to Question #189800 in Python for phani

Question #189800
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 teams 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.
Input

The first line contains a single integer N, denoting the total no. of matches played. 
Names of teams may contain spaces but will be less than 24 characters
100 >= N >= 0
Sample Input 
6
CSK;RR;loss
RR;DD;draw
MI;KKR;win
KKR;RR;loss
CSK;DD;draw
MI;DD;draw
Sample Output 
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-05-09T05:37:04-0400
def main():
    N=int(input())
    if N>=0 and N<=100:
        teamList = {}
        for i in range(N):
            inputTeamData = input().split(';')
            team1 = inputTeamData[0].strip()
            team2 = inputTeamData[1].strip()
            mr = inputTeamData[2].strip()
            
            if(team1 not in teamList):
                teamList[team1]=[0,0,0,0,0]
            if(team2 not in teamList):
                teamList[team2]=[0,0,0,0,0]        
            if(team1 in teamList and team2 in teamList):
                teamList[team1][0]+=1
                teamList[team2][0]+=1
                if mr == 'win':
                    teamList[team1][1]+=1
                    teamList[team2][2]+=1
                elif mr == 'loss':
                    teamList[team1][2]+=1
                    teamList[team2][1]+=1
                elif mr == 'draw':
                    teamList[team1][3]+=1
                    teamList[team2][3]+=1


        for team in teamList:
            teamList[team][4]=teamList[team][1]*3+teamList[team][3]


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



Example:


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
APPROVED BY CLIENTS