From 7cb6cd7cb38ae3dbcb0d57a781b8d8539ab8f768 Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Tue, 26 Nov 2024 20:58:44 +0100 Subject: [PATCH] Solution --- app/main.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index a740cca7..115ad35d 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,19 @@ class OnlineCourse: - # write your code here - pass + def __init__(self, name: str, description: str, weeks: int) -> None: + self.name = name + self.description = description + self.weeks = weeks + + @staticmethod + def days_to_weeks(days: int) -> int: + if days % 7 == 0: + return days // 7 + return days // 7 + 1 + + @classmethod + def from_dict(cls, course_dict: dict) -> "OnlineCourse": + return cls( + name=course_dict["name"], + description=course_dict["description"], + weeks=cls.days_to_weeks(course_dict["days"]) + )