The program is taken on the standard input a list of football team games with the result of the match and displays on the standard output a summary table of the results of all matches.
A team is awarded 3 points for a win, 0 for a loss, and 1 for a draw.
from collections import defaultdict
numberTeams = int(input())
dictTeams = defaultdict(list)
class Score:
def __init__(self, number, dictTeams):
self.number = number
self.dictTeams = dictTeams
self.lengthValue = 0
self.total = 0
self.win, self.draw, self.loss = 0, 0, 0
def appendScore(self):
for i in range(self.number):
rez = input().split(';')
self.dictTeams[rez[0]].append(3 if int(rez[1])>int(rez[3]) else 1 if int(rez[1])==int(rez[3]) else 0)
self.dictTeams[rez[2]].append(3 if int(rez[1])<int(rez[3]) else 1 if int(rez[1])==int(rez[3]) else 0)
def countScore(self):
for letter, value in dictTeams.items():
self.lengthValue = len(value)
self.win, self.draw, self.loss = 0, 0, 0
for i in value:
if i==3: self.win+=1
elif i==1: self.draw+=1
elif i==0: self.loss+=1
self.total = self.win*3+self.draw*1
print(f"{letter}:{self.lengthValue} {self.win} {self.draw} {self.loss} {self.total}")
competition = Score(numberTeams, dictTeams)
competition.appendScore()
competition.countScore()
Possible input:
3
Madrid;4;Spartak;5
Spartak;6;Chelsi;1
Chelsi;3;Madrid;3
Do I need to use classes there?