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' #1359

Open
wants to merge 2 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(team: list) -> int:
return sum(user.get_rating() for user in team)


def elves_concert(elves: list) -> list:
result1 = []
for user_elf in elves:
result1.append(user_elf.play_elf_song())
return result1


def feast_of_the_dwarves(dwarves: list) -> list:
result = []
for user_dwarf in dwarves:
result.append(user_dwarf.eat_favourite_dish())
return result
Empty file added app/players/__init__.py
Empty file.
Empty file added app/players/dwarves/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions app/players/dwarves/dwarf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from abc import ABC
from app.players.player import Player


class Dwarf(Player, ABC):

def __init__(self, nickname: str, favourite_dish: str) -> None:
super().__init__(nickname)
self._favourite_dish = favourite_dish

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


class DwarfBlacksmith(Dwarf):

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

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

def get_rating(self) -> int:
result = self._skill_level
return result
22 changes: 22 additions & 0 deletions app/players/dwarves/dwarf_warrior.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from app.players.dwarves.dwarf import Dwarf


class DwarfWarrior(Dwarf):

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

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

def get_rating(self) -> int:
result = self._hummer_level + 4
return result
Empty file added app/players/elves/__init__.py
Empty file.
22 changes: 22 additions & 0 deletions app/players/elves/druid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from app.players.elves.elf import Elf


class Druid(Elf):

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

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

def get_rating(self) -> int:
result = len(self._favourite_spell)
return result
13 changes: 13 additions & 0 deletions app/players/elves/elf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from abc import ABC
from app.players.player import Player


class Elf(Player, ABC):

def __init__(self, nickname: str, musical_instrument: str) -> None:
super().__init__(nickname)
self._musical_instrument = musical_instrument

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


class ElfRanger(Elf):

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

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

def get_rating(self) -> int:
result = 3 * self._bow_level
return result
15 changes: 15 additions & 0 deletions app/players/player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from abc import ABC, abstractmethod


class Player(ABC):

def __init__(self, nickname: str) -> None:
self.nickname = nickname

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

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