Получение ошибки main () вместе с ошибкой first_league = League ('NBA') - PullRequest
0 голосов
/ 19 июня 2019

Я пытался сделать игру-симулятор. Но затем он продолжает говорить, что есть проблема с main () и first_league = League ('NBA'). Я использовал все, но это не работает.

Вот код Python:

Python

import random

from player import generate_player
from team import League, Team


def main():
    # set up the data
    # set up 8 teams
    # only one manager per team
    # only one league

    players = []
    for i in range(100):
        players.append(generate_player())

    # more teams will be added later on
    teams = [
        Team('Toronto Raptors'),
        Team('Los Angeles Lakers'),
        Team('Houston Rockets'),
        Team("Golden State Warriors"),
        Team('Oklahoma City Thunder'),
        Team('Philadelphia 76ers'),
        Team('Portland Trail Blazers'),
        Team('Milwaukee Bucks'),
    ]

    for team in teams:
        # give them 5 starting players
        for player_num in range(5):
            selected_player = random.choice(players)
            team.players.append(selected_player)
            players.remove(selected_player)

    # one league
    first_league = League('NBA')
    first_league.set_teams(teams)

    first_league.play_season()


if __name__ == '__main__':
    main()

Вот класс лиги из командного модуля:

class League:
    """
    Has different teams that consists in it
    Each team has a ranking
    """

    def __init__(self, name, play_season):
        self.name = name
        self.teams = []

    def set_teams(self, teams):
        self.teams = teams

    def play_season(self):
        """
        play 30 games in the regular season
        """
        for i in range(30):
            self.play_regular()

    def play_playoffs(self):
        """
        8 teams play for the championship
         -First round  8
          -Semi Finals 4
           -The Finals 2
             -Winner   1
        """
        num_teams = len(self.teams)
        num_games = num_teams // 2

        teams_to_play = copy.copy(self.teams)

        for game_num in range(num_games):
            home_team = random.choice(teams_to_play)
            teams_to_play.remove(home_team)
            away_team = random.choice(teams_to_play)
            teams_to_play.remove(away_team)

            game = Game(self, home_team, away_team)
            winner = game.play()

            if winner:
                # home team won
                home_team.wins += 1
                away_team.losses += 1
            else:
                # away team won
                away_team.wins += 1
                home_team.losses += 1

Теперь вот ошибка с консоли:

Консоль

Traceback (most recent call last):
  File "C:/Users/josep/PycharmProjects/NBA_Fantasy/main.py", line 44, in <module>
    main()
  File "C:/Users/josep/PycharmProjects/NBA_Fantasy/main.py", line 37, in main
    first_league = League('NBA')
TypeError: __init__() missing 1 required positional argument: 'play_season'

Пожалуйста, скажите мне, что не так в коде, и помогите мне решить его. Спасибо!

...