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 list
if team in teams:
points = teams[team]
#else set to 0
else:
points = [0,0,0]
#points[win,loss,draw]
result = result.lower()
if(result=="won"):
points[0] +=1
elif(result=="loss"):
points[1] +=1
else:
points[2] +=1
#update teams
teams[team] = points
''' calculate result to be displayed '''
def calc_result(teams):
list_res= list()
for team in teams:
won,lost,draw = teams[team]
#calculate points
points = 2*won + draw
#total matches played
total = won+lost+draw
#string to be displayed
string = 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 team1
add_teams(ip[0],ip[2],teams)
#for team2, reverse the result
if(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
- Composite Number in Python
- Greatest Among Four Numbers in Python
- Reverse the sentence in Python
- Denominations in Python
- Min and max values in an array in JavaScript
- Keyboard events in JavaScript
- Reaching Ground Floor in Python
- Number of Moves in Python
- Starks Adventure in Python
- Neutralization in Python | Assignment Expert
- Free shipping in Python
- Raj has ordered two electronic items Python | Assignment Expert
- First Place in Python
- Triples with Properties in Python
- Nested list Indexing Python
- Team Points in Python
- Two words combination in Python
- ID Card in Python
- Cipher with a key in Python | Assignment Expert
- Multiple of 5 in Python
- Sandglass Star in Python
- Multiple of 3 in Python | Assignment Expert
- Ticket selling in Cricket Stadium using Python | Assignment Expert
- Sum of List Elements in Python
- All possible subsets in Python
- Names and Nicknames in Python

