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 #1227

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 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
47 changes: 45 additions & 2 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
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:
"""
Convert days to weeks.

Args:
days (int): The number of days.

Returns:
int: The number of weeks (round up for any extra days).
"""
return (days + 6) // 7 # Round up to the next week if there are extra days.

@classmethod
def from_dict(cls, course_dict: dict) -> "OnlineCourse":
"""
Create an instance of OnlineCourse from a dictionary.

Args:
cls: The class itself.
course_dict (dict): A dictionary with course data.

Returns:
OnlineCourse: A new instance of the class.
"""
weeks = cls.days_to_weeks(course_dict["days"])
return cls(
name=course_dict["name"],
description=course_dict["description"],
weeks=weeks
)

# Example usage
course_dict = {
"name": "Python Core",
"description": (
"After this course you will know everything about Python"
),
"days": 12,
}
Loading