From f4b1f2967d140f6ed05e2e6de565c6f0b333240b Mon Sep 17 00:00:00 2001 From: Ihor Halytskiy Date: Mon, 2 Dec 2024 22:01:16 +0200 Subject: [PATCH] Create Task Online course --- app/main.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index a740cca7..78c36ab1 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,22 @@ +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: + tail = 0 if days % 7 == 0 else 1 + return days // 7 + tail + + @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"]) + )