Write a program that reads all the match outcomes and summarizes the information of all the matches. A win earns a team 3 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.
The following N lines contain outcomes of N matches. Each of those lines has information on the teams (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. The team name may contain spaces.
Output:
The output should contain summarized information of all the matches in a format similar to 'Team: 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
team = {}
matches = int(input('Enter the number of matches played: '))
# data input
for match in range(matches):
data_match = input(f'Enter data for {match +1} match: ')
team_1, team_2, outcome = data_match.split(';')
if team_1 not in team:
team[team_1] = [0,0,0,0,0]
if team_2 not in team:
team[team_2] = [0,0,0,0,0]
team[team_1][0] +=1
team[team_2][0] += 1
if outcome == 'win':
team[team_1][1] += 1
team[team_1][4] += 3
team[team_2][3] += 1
elif outcome == 'loss':
team[team_2][1] += 1
team[team_2][4] += 3
team[team_1][3] += 1
elif outcome == 'draw':
team[team_1][2] += 1
team[team_2][2] += 1
team[team_1][4] += 1
team[team_2][4] += 1
# data output
team_list=sorted(team.items(),key=lambda t:t[1][4],reverse=True)
for item in team_list:
print(f'Team: {item[0]}')
print(f'MP: {item[1][0]}')
print(f'W: {item[1][1]}')
print(f'D: {item[1][2]}')
print(f'L: {item[1][3]}')
print(f'P: {item[1][4]}')
Comments
Leave a comment