-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b435d0
commit 4c928eb
Showing
1 changed file
with
14 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
from typing import Dict | ||
|
||
|
||
class OnlineCourse: | ||
# Метод __init__ для ініціалізації об'єкта класу | ||
def __init__(self, name, description, weeks): | ||
self.name = name | ||
self.description = description | ||
self.weeks = weeks | ||
def __init__(self, name: str, description: str, weeks: int) -> None: | ||
self.name: str = name | ||
self.description: str = description | ||
self.weeks: int = weeks | ||
|
||
# Статичний метод для конвертації днів у тижні | ||
@staticmethod | ||
def days_to_weeks(days): | ||
# Округлення вгору для врахування неповного тижня | ||
def days_to_weeks(days: int) -> int: | ||
return (days + 6) // 7 | ||
|
||
# Класовий метод для створення об'єкта на основі словника | ||
@classmethod | ||
def from_dict(cls, course_dict): | ||
name = course_dict["name"] | ||
description = course_dict["description"] | ||
days = course_dict["days"] | ||
weeks = cls.days_to_weeks(days) # Використовуємо days_to_weeks для конвертації | ||
return cls(name, description, weeks) # Створюємо новий об'єкт класу | ||
def from_dict(cls, course_dict: Dict[str, str | int]) -> "OnlineCourse": | ||
name: str = course_dict["name"] | ||
description: str = course_dict["description"] | ||
days: int = course_dict["days"] | ||
weeks: int = cls.days_to_weeks(days) | ||
return cls(name, description, weeks) |