/
elder247
/
aaa-python-advanced
Обзор
Документация
Войти
/
elder247
/
aaa-python-advanced
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
hw_1/task_2.py
74 строки
2 KB
Anton Trofimuk
add docstrings
02 дек 2024, 14:28
02 дек 2024, 14:28
92bfe3b
Код
Авторство
О чём код?
from abc import ABC, abstractmethod class EmojiMixin: """ Contains emojis for basic Pokemon's categories """ category_to_emoji = { 'grass': '🌿', 'fire': '🔥', 'water': '🌊', 'electric': '⚡' } def get_emoji(self): """ :return: emoji based on Pokemon's category """ emoji = self.category_to_emoji.get(self.category, 'no type') return emoji class PokemonTrainInterface(ABC): """ Abstract class for Pokemon, who have experience and can increase it """ @property @abstractmethod def experience(self): pass @abstractmethod def increase_experience(self, value): pass class BasePokemon(PokemonTrainInterface): """ Base class for Pokemon with start experience 100 """ def __init__(self): self._experience = 100 @property def experience(self): return self._experience def increase_experience(self, value): self._experience += value class Pokemon(EmojiMixin, BasePokemon): """ Class for Pokemons who have emoji and experience """ def __init__(self, name: str, category: str): super().__init__() self.name = name self.category = category def __str__(self): return f'{self.name}/{super().get_emoji()}' if __name__ == '__main__': pikachu = Pokemon(name='Pikachu', category='electric') print(pikachu) bulbasaur = Pokemon(name='Bulbasaur', category='grass') print(bulbasaur) assert bulbasaur.experience == 100, 'Default value != 100' bulbasaur.increase_experience(100) assert bulbasaur.experience == 200, 'Try harder, Neeman'