Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Solution' #1176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
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:
if not isinstance(days, int):
raise TypeError("days must be an integer.")
return -(-days // 7)

@classmethod
def from_dict(cls, course_dict: dict) -> OnlineCourse:
if not isinstance(course_dict, dict):
raise TypeError("course_dict must be a dictionary.")
required_keys = ["name", "description", "days"]
for key in required_keys:
if key not in course_dict:
raise ValueError(f"Missing required key: {key}")
name = course_dict["name"]
description = course_dict["description"]
days = course_dict["days"]
if not isinstance(name, str):
raise TypeError(f"Expected 'name' "
f"to be a string, got {type(name).__name__}.")
if not isinstance(description, str):
raise TypeError(f"Expected 'description' to be a string, "
f"got {type(description).__name__}.")
if not isinstance(days, int):
raise TypeError(f"Expected 'days' "
f"to be an integer, got {type(days).__name__}.")
weeks = cls.days_to_weeks(days)
return cls(name=name, description=description, weeks=weeks)
Loading