/
vibrosiq
/
programming_practice
Обзор
Документация
Войти
/
vibrosiq
/
programming_practice
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
27.10/book.py
43 строки
1 KB
Варвара Бронникова
update 27.10/book.py
09 янв 2026, 21:17
09 янв 2026, 21:17
f0f4e4b
Код
Авторство
О чём код?
from datetime import datetime from abc import ABC, abstractmethod from typing import Self class Printable(ABC): @abstractmethod def print_info(self) -> str: pass class Book(Printable): def __init__(self, title: str, author: str, year: int): self.title = title self.author = author self.year = year def info(self) -> str: return f"Название: {self.title}, Автор: {self.author}, Год: {self.year}" def __str__(self) -> str: return self.info() def __eq__(self, other: object) -> bool: return isinstance(other, Book) and self.title == other.title def print_info(self) -> str: return self.info() @property def age(self) -> int: return datetime.now().year - self.year @classmethod def from_string(cls, data: str) -> Self: title, author, year = data.split(';') return cls(title, author, int(year)) class EBook(Book): def __init__(self, title: str, author: str, year: int, file_format: str): super().__init__(title, author, year) self.file_format = file_format def info(self) -> str: return f"{super().info()} [Формат: {self.file_format}]"