-
Notifications
You must be signed in to change notification settings - Fork 22
Караманов Карим Ильнурович 25б42 #10
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
Open
karikprog
wants to merge
6
commits into
python-course-matmex:main
Choose a base branch
from
karikprog:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c6b0af0
добавление .gitignore и .python-version исправление бинарного поиска …
karikprog ac6e53f
проверка количества элементов
karikprog e190a48
Уменьшение переменной weight
karikprog 141ffae
ДОбавление корректной обработки X
karikprog 8c3ccd0
Добавление и исправление тестов для isbn, исправление ошибки при импорте
karikprog c112c79
Смена языка в утилите
karikprog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ### VisualStudioCode ### | ||
| .vscode/* | ||
| !.vscode/settings.json | ||
| !.vscode/tasks.json | ||
| !.vscode/launch.json | ||
| !.vscode/extensions.json | ||
| !.vscode/*.code-snippets | ||
|
|
||
| # Local History for Visual Studio Code | ||
| .history/ | ||
|
|
||
| # Built Visual Studio Code Extensions | ||
| *.vsix | ||
|
|
||
| ### VisualStudioCode Patch ### | ||
| # Ignore all local history of files | ||
| .history | ||
| .ionide | ||
|
|
||
| venv | ||
|
|
||
| __pycache__ | ||
| .pytest_cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 3.12.3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,31 @@ | ||
| def modulo11Checksum(ISBNNumber: str): | ||
| def modulo_11_checksum(isbn_number: str): | ||
| digits = isbn_number.replace("-", "").replace(" ", "") | ||
|
|
||
| digits = [int(char) for char in ISBNNumber if char.isdigit()] | ||
|
|
||
| checkDigit = digits[-1] | ||
| if len(digits) != 10: | ||
| return False | ||
|
|
||
| total = 0 | ||
| for i in range(len(digits) - 1): | ||
| weight = 10 | ||
| for i in range(10): | ||
| digit = digits[i] | ||
| total += digit * weight | ||
|
|
||
| checksum = total + checkDigit | ||
| return checksum % 11 == 0 | ||
| if digit.upper() == "X" and i == 9: | ||
| val = 10 | ||
| elif digit.isdigit(): | ||
| val = int(digit) | ||
| else: | ||
| return False | ||
| weight = 10 - i | ||
| total += val * weight | ||
|
|
||
| return total % 11 == 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| while True: | ||
| isbn_string = input("Put number(-1 exit): ") | ||
| if isbn_string == "-1": | ||
| break | ||
| if modulo_11_checksum(isbn_string): | ||
| print("Correct") | ||
| else: | ||
| print("Incorrect") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,17 @@ | ||
| from src.bin_search import binSearch | ||
| from src.bin_search import bin_search | ||
|
|
||
|
|
||
| def test_middle(): | ||
| assert binSearch([1, 2, 3, 4, 5], 4) == 3 | ||
| assert bin_search([1, 2, 3, 4, 5], 4) == 3 | ||
|
|
||
|
|
||
| def test_start(): | ||
| assert binSearch([1, 2, 3, 4], 2) == 1 | ||
| assert bin_search([1, 2, 3, 4], 2) == 1 | ||
|
|
||
|
|
||
| def test_one_value(): | ||
| assert bin_search([6], 6) == 0 | ||
|
|
||
|
|
||
| def test_not_in_list(): | ||
| assert binSearch([1, 2, 3, 4], 5) == -1 | ||
| assert bin_search([1, 2, 3, 4], 5) == -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| from src.checksum import modulo11Checksum | ||
| from src.checksum import modulo_11_checksum | ||
|
|
||
|
|
||
| def test_good(): | ||
| assert modulo11Checksum("2-266-11156-8") | ||
| assert modulo_11_checksum("0-306-40615-2") | ||
|
|
||
|
|
||
| def test_whith_x(): | ||
| assert modulo_11_checksum("0-8044-2957-X") | ||
|
|
||
|
|
||
| def test_bad(): | ||
| assert not modulo11Checksum("2-266-11156-3") | ||
| assert not modulo_11_checksum("2-266-11156-3") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Рекомендация: при неверной длине строки лучше выбрасывать исключение, чтобы различать некорректный формат входных данных и просто невалидную контрольную сумму.
Тогда в вызывающем коде нужно будет добавить блок try-except.