From db40075cc2e8672e0aa32bfcade00e611e9d21a5 Mon Sep 17 00:00:00 2001 From: Volodimir Date: Wed, 20 Nov 2024 17:43:02 +0200 Subject: [PATCH] 'Solution' --- app/main.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index a740cca7..528d658b 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,35 @@ class OnlineCourse: - # write your code here - pass + def __init__(self, name: str, description: str, weeks: int) -> None: + """ + Initialize the OnlineCourse instance. + + :param name: Name of the course. + :param description: Description of the course. + :param weeks: Duration of the course in weeks. + """ + self.name = name + self.description = description + self.weeks = weeks + + @staticmethod + def days_to_weeks(days: int) -> int: + """ + Convert course duration from days to weeks. + + :param days: Duration of the course in days. + :return: Equivalent duration in weeks. + """ + return (days + 6) // 7 # Adding 6 ensures that partial weeks round up. + + @classmethod + def from_dict(cls, course_dict: dict) -> "OnlineCourse": + """ + Create an OnlineCourse instance from a dictionary. + + :param course_dict: Dictionary with course information. + :return: An instance of OnlineCourse. + """ + name = course_dict["name"] + description = course_dict["description"] + weeks = cls.days_to_weeks(course_dict["days"]) + return cls(name=name, description=description, weeks=weeks)