From 04d77a9e69e77ada1c1242958fb356fdc5686682 Mon Sep 17 00:00:00 2001 From: Maskym Chukhno Date: Tue, 5 Nov 2024 17:30:57 +0200 Subject: [PATCH] Solution --- .flake8 | 2 +- .gitignore | 1 + app/main.py | 24 ++++++++++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.flake8 b/.flake8 index d7459204..3f5e06ff 100644 --- a/.flake8 +++ b/.flake8 @@ -4,4 +4,4 @@ ignore = E203, E266, W503, ANN002, ANN003, ANN101, ANN102, ANN401, N807, N818 max-line-length = 79 max-complexity = 18 select = B,C,E,F,W,T4,B9,ANN,Q0,N8,VNE -exclude = venv, tests +exclude = venv, tests, .venv diff --git a/.gitignore b/.gitignore index b26d6116..0a632a90 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ venv/ .pytest_cache/ **__pycache__/ +.venv \ No newline at end of file diff --git a/app/main.py b/app/main.py index a740cca7..e1afbf64 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,23 @@ +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) -> int: + return math.ceil(days / 7) + + @classmethod + def from_dict(cls, course_dict: dict) -> dict: + weeks = cls.days_to_weeks(course_dict["days"]) + + return cls( + name=course_dict["name"], + description=course_dict["description"], + weeks=weeks + )