Answer to Question #244290 in Python for balu

Question #244290

IPL

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


Each of those lines has information on the T1, T2) which played and the outcome (O) in format T1;T2;O.

The outcome (O) is one of 'win', 'loss', 'draw' and refers to the first team listed.

See Sample Input/Output for better understanding.

CSK, Matches Played: 4, Won: 2, Lost: 1, Draw: 1, Points: 7' for each team in a new line.

If there are no teams to print in summary, print "No Output".

Constraints


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




1
Expert's answer
2021-09-30T00:57:44-0400
def main():
    N=int(input("Enter the number of matches: "))
    if N>=0 and N<=100:
        Team_L = {}
        for i in range(N):
            EnterInfo = input().split(';')
            t1 = EnterInfo[0].strip()
            t2 = EnterInfo[1].strip()
            mr = EnterInfo[2].strip()
            
            if(t1 not in Team_L):
                Team_L[t1]=[0,0,0,0,0]
            if(t2 not in Team_L):
                Team_L[t2]=[0,0,0,0,0]        
            if(t1 in Team_L and t2 in Team_L):
                Team_L[t1][0]+=1
                Team_L[t2][0]+=1
                if mr == 'win':
                    Team_L[t1][1]+=1
                    Team_L[t2][2]+=1
                elif mr == 'loss':
                    Team_L[t1][2]+=1
                    Team_L[t2][1]+=1
                elif mr == 'draw':
                    Team_L[t1][3]+=1
                    Team_L[t2][3]+=1




        for t in Team_L:
            Team_L[t][4]=Team_L[t][1]*3+Team_L[t][3]




    for t in (sorted(Team_L.items(), key = lambda points: points[1][4],reverse=True)):
        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() 

Sample output:

Enter the number of matches: 6

CSK;RR;loss

RR;DD;draw

MI;KKR;win

KKR;RR;loss

CSK;DD;draw

MI;DD;draw

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


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