0
\$\begingroup\$

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?

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Could you provide a sample input, for the benefit of those who would like to run your code? That might help get you better reviews. \$\endgroup\$ Nov 24, 2022 at 14:14
  • \$\begingroup\$ @TobySpeight input: 3 \n Madrid;4;Spartak;5 \n Spartak;6;Chelsi;1 \n Chelsi;3;Madrid;3 \$\endgroup\$ Nov 24, 2022 at 14:35
  • 1
    \$\begingroup\$ I've edited your question to include that. Normally that's something you should do yourself. \$\endgroup\$ Nov 24, 2022 at 16:49
  • \$\begingroup\$ @TobySpeight thanks. \$\endgroup\$ Nov 24, 2022 at 20:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.