Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution #1357

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# write your code here

def calculate_team_total_rating(players: list) -> int:
result = 0
for player in players:
result += player.get_rating()
return result


def elves_concert(elves: list) -> None:
for elf in elves:
elf.play_elf_song()


def feast_of_the_dwarves(dwarfs: list) -> None:
for dwarf in dwarfs:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name dwarfs should be dwarves to match the task description and maintain consistency with the naming convention used elsewhere in the code.

dwarf.eat_favourite_dish()
13 changes: 13 additions & 0 deletions app/players/dwarves/dwarf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from abc import ABC, abstractmethod

from app.players.player import Player


class Dwarf(Player, ABC):
def __init__(self, favourite_dish: str) -> None:
self.nickname = None
self._favourite_dish = favourite_dish

@abstractmethod
def eat_favourite_dish(self) -> None:
print(f"{self.nickname} is eating {self._favourite_dish}")
19 changes: 19 additions & 0 deletions app/players/dwarves/dwarf_blacksmith.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from app.players.dwarves.dwarf import Dwarf


class DwarfBlacksmith(Dwarf):
def __init__(self, nickname: str, skill_level: int,
favourite_dish: str) -> None:
super().__init__(favourite_dish)
self._skill_level = skill_level
self._nickname = nickname

def player_info(self) -> str:
return (f"Dwarf blacksmith {self._nickname} with skill "
f"of the {self._skill_level} level")

def get_rating(self) -> int:
return self._skill_level

def eat_favourite_dish(self) -> None:
print(f"{self._nickname} is eating {self._favourite_dish}")
19 changes: 19 additions & 0 deletions app/players/dwarves/dwarf_warrior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from app.players.dwarves.dwarf import Dwarf


class DwarfWarrior(Dwarf):
def __init__(self, nickname: str,
hummer_level: int, favourite_dish: str) -> None:
super().__init__(favourite_dish)
self._hummer_level = hummer_level
self._nickname = nickname

def player_info(self) -> str:
return (f"Dwarf warrior {self._nickname}. {self._nickname} "
f"has a hummer of the {self._hummer_level} level")

def get_rating(self) -> int:
return self._hummer_level + 4

def eat_favourite_dish(self) -> None:
print(f"{self._nickname} is eating {self._favourite_dish}")
20 changes: 20 additions & 0 deletions app/players/elves/druid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from app.players.elves.elf import Elf


class Druid(Elf):
def __init__(self, nickname: str, favourite_spell: str,
musical_instrument: str) -> None:
super().__init__(musical_instrument)
self._favourite_spell = favourite_spell
self._nickname = nickname

def player_info(self) -> str:
return (f"Druid {self._nickname}. {self._nickname} has a"
f" favourite spell: {self._favourite_spell}")

def get_rating(self) -> int:
return len(self._favourite_spell)

def play_elf_song(self) -> None:
print(f"{self._nickname} is playing a song "
f"on the {self._musical_instrument}")
14 changes: 14 additions & 0 deletions app/players/elves/elf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from abc import ABC, abstractmethod

from app.players.player import Player


class Elf(Player, ABC):
def __init__(self, musical_instrument: str) -> None:
self.nickname = None
self._musical_instrument = musical_instrument

@abstractmethod
def play_elf_song(self) -> None:
print(f"{self.nickname} is playing a song "
f"on the {self._musical_instrument}")
20 changes: 20 additions & 0 deletions app/players/elves/elf_ranger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from app.players.elves.elf import Elf


class ElfRanger(Elf):
def __init__(self, nickname: str, bow_level: int,
musical_instrument: str) -> None:
super().__init__(musical_instrument)
self._bow_level = bow_level
self._nickname = nickname

def player_info(self) -> str:
return (f"Elf ranger {self._nickname}. {self._nickname} "
f"has bow of the {self._bow_level} level")

def get_rating(self) -> int:
return 3 * self._bow_level

def play_elf_song(self) -> None:
print(f"{self._nickname} is playing a "
f"song on the {self._musical_instrument}")
13 changes: 13 additions & 0 deletions app/players/player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from abc import ABC, abstractmethod


class Player(ABC):
_nickname = ""

@abstractmethod
def get_rating(self) -> int:
pass

@abstractmethod
def player_info(self) -> str:
pass
Loading