From e2d7858a8c543cf76d749a559eb923cb192f9455 Mon Sep 17 00:00:00 2001 From: Diana Zatvarska Date: Sat, 14 Dec 2024 16:39:59 -0800 Subject: [PATCH] Solution --- app/main.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index a740cca7..9b6b51ce 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,22 @@ +import math + + 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) -> "OnlineCourse.weeks": + return math.ceil(days / 7) + + @classmethod + def from_dict(cls, course_dict: dict) -> "OnlineCourse": + if course_dict is None: + return None + return cls( + name=course_dict["name"], + description=course_dict["description"], + weeks=OnlineCourse.days_to_weeks(course_dict["days"]), + )