From b7ee498127c024fee09298b6920a718239662c1f Mon Sep 17 00:00:00 2001 From: Max Savenya Date: Sun, 20 Oct 2024 21:40:22 +0300 Subject: [PATCH] Solution --- app/main.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index a740cca7..6fcdb493 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,28 @@ +from __future__ import annotations + + 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: + weeks = 0 + + while days > 0: + days -= 7 + weeks += 1 + + return weeks + + @classmethod + def from_dict(cls, course_dict: dict) -> OnlineCourse: + name = course_dict["name"] + description = course_dict["description"] + days = course_dict["days"] + + weeks = cls.days_to_weeks(days) + + return cls(name, description, weeks)