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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[flake8]
inline-quotes = "
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
[flake8]
inline-quotes = "
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
74 changes: 37 additions & 37 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
name: Test

on: [push, pull_request_target]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}

- name: Set Up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"

- name: Install pytest and flake8
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run flake8
run: flake8 app/
- name: Run tests
timeout-minutes: 5
run: pytest tests/
- uses: mate-academy/auto-approve-action@v2
if: ${{ github.event.pull_request && success() }}
with:
github-token: ${{ github.token }}
- uses: mate-academy/auto-reject-action@v2
if: ${{ github.event.pull_request && failure() }}
with:
github-token: ${{ github.token }}
name: Test
on: [push, pull_request_target]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
ref: ${{github.event.pull_request.head.ref}}
repository: ${{github.event.pull_request.head.repo.full_name}}
- name: Set Up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install pytest and flake8
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run flake8
run: flake8 app/
- name: Run tests
timeout-minutes: 5
run: pytest tests/
- uses: mate-academy/auto-approve-action@v2
if: ${{ github.event.pull_request && success() }}
with:
github-token: ${{ github.token }}
- uses: mate-academy/auto-reject-action@v2
if: ${{ github.event.pull_request && failure() }}
with:
github-token: ${{ github.token }}
16 changes: 8 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.idea/
.vscode/
*.iml
.env
.DS_Store
venv/
.pytest_cache/
**__pycache__/
.idea/
.vscode/
*.iml
.env
.DS_Store
venv/
.pytest_cache/
**__pycache__/
114 changes: 57 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
# Online Course

- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before start

We want to create a website for finding the best online courses.
In order to store information about courses, we need a new `OnlineCourse` class.
Could you implement it for us?

`OnlineCourse` `__init__` method takes three arguments:
* `name` - course name (should be stored in `self.name`)
* `description` - course description (should be stored in `self.description`)
* `weeks` - duration of the course in weeks (should be stored in `self.weeks`)

```python
course = OnlineCourse(
name="Python Basics",
description="The best course to start learning Python",
weeks=2,
)
print(course.description) # The best course to start learn Python
```

Often we will receive information about the course in the form of a `course_dict` dictionary
with such fields:
* `course_dict["name"]` - course name
* `course_dict["description"]` - course description
* `course_dict["days"]` - duration of the course in days

To convert course duration to weeks, `OnlineCourse` should have `days_to_weeks` **staticmethod**,
that takes one argument `days` and convert this number to weeks.

Note: The last week may not be whole.

Example:
```python
OnlineCourse.days_to_weeks(10) == 2
OnlineCourse.days_to_weeks(14) == 2
OnlineCourse.days_to_weeks(15) == 3
```

`OnlineCourse` should have `from_dict` **classmethod**. It should take
two parameters:
* `cls` - a default parameter for classmethod
* `course_dict` - a dictionary described above

Method should return a new instance of `OnlineCourse` with correct attributes.
It should use `days_to_weeks` method to convert days to weeks.
Example:
```python
course_dict = {
"name": "Python Core",
"description": "After this course you will know everything about Python",
"days": 12,
}
python_course = OnlineCourse.from_dict(course_dict)
print(python_course.weeks) # 2
```
# Online Course
- Read [the guideline](https://github.com/mate-academy/py-task-guideline/blob/main/README.md) before start
We want to create a website for finding the best online courses.
In order to store information about courses, we need a new `OnlineCourse` class.
Could you implement it for us?
`OnlineCourse` `__init__` method takes three arguments:
* `name` - course name (should be stored in `self.name`)
* `description` - course description (should be stored in `self.description`)
* `weeks` - duration of the course in weeks (should be stored in `self.weeks`)
```python
course = OnlineCourse(
name="Python Basics",
description="The best course to start learning Python",
weeks=2,
)
print(course.description) # The best course to start learn Python
```
Often we will receive information about the course in the form of a `course_dict` dictionary
with such fields:
* `course_dict["name"]` - course name
* `course_dict["description"]` - course description
* `course_dict["days"]` - duration of the course in days
To convert course duration to weeks, `OnlineCourse` should have `days_to_weeks` **staticmethod**,
that takes one argument `days` and convert this number to weeks.
Note: The last week may not be whole.
Example:
```python
OnlineCourse.days_to_weeks(10) == 2
OnlineCourse.days_to_weeks(14) == 2
OnlineCourse.days_to_weeks(15) == 3
```
`OnlineCourse` should have `from_dict` **classmethod**. It should take
two parameters:
* `cls` - a default parameter for classmethod
* `course_dict` - a dictionary described above
Method should return a new instance of `OnlineCourse` with correct attributes.
It should use `days_to_weeks` method to convert days to weeks.
Example:
```python
course_dict = {
"name": "Python Core",
"description": "After this course you will know everything about Python",
"days": 12,
}
python_course = OnlineCourse.from_dict(course_dict)
print(python_course.weeks) # 2
```
25 changes: 22 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
class OnlineCourse:
# write your code here
pass
from __future__ import annotations


class OnlineCourse:

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 days % 7 > 0:
return (days // 7) + 1
return days // 7

@classmethod
def from_dict(cls, course_dict: dict) -> OnlineCourse:
name = course_dict["name"]
description = course_dict["description"]
weeks = cls.days_to_weeks(course_dict["days"])
return cls(name, description, weeks)
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
flake8==5.0.4
flake8-annotations==2.9.1
flake8-quotes==3.3.1
flake8-variables-names==0.0.5
pep8-naming==0.13.2
pytest==7.1.3
flake8==5.0.4
flake8-annotations==2.9.1
flake8-quotes==3.3.1
flake8-variables-names==0.0.5
pep8-naming==0.13.2
pytest==7.1.3
Loading
Loading