Answer the question
In order to leave comments, you need to log in
Task from stepik. How do I fix the listing issue?
I suffered, put on crutches, and still it doesn’t work. The mistake is that the results of one team (Lokomotiv) change with the results of the second team (Spartak).
n = int(input())
teams = dict()
for i in range(n):
team1, r1, team2, r2= input().split(';')
if team1 not in teams.keys():
teams[team1] = [0, 0, 0, 0, 0]
if team2 not in teams.keys():
teams[team2] = [0, 0, 0, 0, 0]
teams[team1][0] += 1
teams[team2][0] += 1
if r1> r2:
teams[team1][1] += 1
teams[team1][4] += 3
teams[team2][3] += 1
elif r1< r2:
teams[team2][1] += 1
teams[team2][4] += 3
teams[team1][3] += 1
else:
teams[team2][2] += 1
teams[team2][4] += 1
teams[team1][2] += 1
teams[team1][4] += 1
for key, value in teams.items():
print(key, end=':')
for v in value:
print(v, end=' ')
print()
Answer the question
In order to leave comments, you need to log in
The most basic problem in your code is incorrect type comparison.
Here in this line you get the name of the team and its points, but all these variables are of type string.
team1, r1, team2, r2=input().split(';')
import collections
results = collections.defaultdict(list)
n = int(input())
for _ in range(n):
team1, score1, team2, score2 = input().strip().split(';')
score1 = int(score1)
score2 = int(score2)
if score1 == score2:
results[team1].append(1)
results[team2].append(1)
continue
if score1 > score2:
results[team1].append(3)
results[team2].append(0)
else:
results[team2].append(3)
results[team1].append(0)
for team, scores in results.items():
games = str(len(scores))
wins = str(scores.count(3))
draws = str(scores.count(1))
loses = str(scores.count(0))
total = str(sum(scores))
print('%s:%s' % (team, ' '.join((games, wins, draws, loses, total))))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question