Problem Statement:
This is IPL and matches are going on. You are a programmer who writes programs to output summarized charts of matches already played.
You will be given some input and you need to print a summarized chart in descending order of points.
Points criteria->
Match won-> 2
Draw-> 1
Loss-> 0
For example
Input:
4
RR-RCB-loss
MI-KKR-loss
CSK-RR-win
GT-RCB-draw
Output:
Team: RR | Total Matches: 2 | Won: 0, Lost: 2, Draw: 0, Points: 0
Team: RCB | Total Matches: 2 | Won: 1, Lost: 0, Draw: 1, Points: 3
Team: MI | Total Matches: 1 | Won: 0, Lost: 1, Draw: 0, Points: 0
Team: KKR | Total Matches: 1 | Won: 1, Lost: 0, Draw: 0, Points: 2
Team: CSK | Total Matches: 1 | Won: 1, Lost: 0, Draw: 0, Points: 2
Team: GT | Total Matches: 1 | Won: 0, Lost: 0, Draw: 1, Points: 1
Code to find Team Points in Python:
''' Add teams to dictionary '''def add_teams(team,result,teams):#if team already exists in list, update the listif team in teams:points = teams[team]#else set to 0else:points = [0,0,0]#points[win,loss,draw]result = result.lower()if(result=="won"):points[0] +=1elif(result=="loss"):points[1] +=1else:points[2] +=1#update teamsteams[team] = points''' calculate result to be displayed '''def calc_result(teams):list_res= list()for team in teams:won,lost,draw = teams[team]#calculate pointspoints = 2*won + draw#total matches playedtotal = won+lost+draw#string to be displayedstring = f"Team: {team} | Total Matches: {total} | Won: {won}, Lost: {lost}, Draw: {draw}, Points: {points}"list_res.append(string)return list_res''' main function '''n=int(input("Number of Matches Played: "))teams=dict()for i in range(n):ip = input().split("-")# ip[0]: team played | ip[1]: against team | ip[2]: result#for team1add_teams(ip[0],ip[2],teams)#for team2, reverse the resultif(ip[2]=="win"):add_teams(ip[1],"loss",teams)elif(ip[2]=="loss"):add_teams(ip[1],"win",teams)else:add_teams(ip[1],"draw",teams)'''result to display'''res = calc_result(teams)'''display the results'''for string in res:print(string)
Output:

Also Read:
- Hyphenate Letters in Python
- Earthquake in Python | Easy Calculation
- Striped Rectangle in Python
- Perpendicular Words in Python
- Free shipping in Python
- Raj has ordered two electronic items Python | Assignment Expert
- Team Points in Python
- Ticket selling in Cricket Stadium using Python | Assignment Expert
- Split the sentence in Python
- String Slicing in JavaScript
- First and Last Digits in Python | Assignment Expert
- List Indexing in Python
- Date Format in Python | Assignment Expert
- New Year Countdown in Python
- Add Two Polynomials in Python
- Sum of even numbers in Python | Assignment Expert
- Evens and Odds in Python
- A Game of Letters in Python
- Sum of non-primes in Python
- Smallest Missing Number in Python
- String Rotation in Python
- Secret Message in Python
- Word Mix in Python
- Single Digit Number in Python
- Shift Numbers in Python | Assignment Expert
- Weekend in Python
- Shift Numbers in Python | Assignment Expert
- Temperature Conversion in Python
- Special Characters in Python
- Sum of Prime Numbers in the Input in Python