Dolzhenko kr 1 python #14
Open
DolzhenkoAlexa wants to merge 7 commits intopython-course-matmex:mainfrom
Open
Conversation
…e, ruff checks were passed
Godrik0
reviewed
Dec 13, 2025
Godrik0
left a comment
There was a problem hiding this comment.
ISBN: 5/10
Бинарный поиск: 5/5
Оформление: 10/10
There was a problem hiding this comment.
В задании требовалось также реализовать консольную утилиту.
Comment on lines
+1
to
+24
| def modulo_11_check_sum(isbn_number: str): | ||
| if not isbn_number: # Обработка случая пустой строки | ||
| return False | ||
|
|
||
| # Извлекаем только цифры, без других символов | ||
| digits = [int(char) for char in isbn_number if char.isdigit()] | ||
|
|
||
| # Проверяем что цифр достаточно | ||
| if len(digits) < 2: | ||
| return False | ||
|
|
||
| check_digit = digits[-1] | ||
| total = 0 | ||
|
|
||
| # Неправильно написан алгоритм | ||
| # Веса должны уменьшаться с 10 до 1, на шаг -1 | ||
| for i in range(len(digits) - 1): | ||
| weight = 10 - i # Веса уменьшаются от 10 до 1 | ||
| digit = digits[i] | ||
| total += digit * weight | ||
|
|
||
| # Проверка контрольной суммы | ||
| checksum = total % 11 | ||
| return checksum == check_digit |
There was a problem hiding this comment.
У Вас пропущена обработка символа X, который может служить контрольной цифрой.
Comment on lines
+23
to
+24
| checksum = total % 11 | ||
| return checksum == check_digit |
There was a problem hiding this comment.
Ошибка в логике.
Нужно было либо оставить checksum = total + checkDigit и сравнивать остаток от деления на 11 с 0.
Либо высчитывать вот так (11 - (sum % 11)) % 11 и тогда уже сравнивать с контрольной цифрой.
| digits = [int(char) for char in isbn_number if char.isdigit()] | ||
|
|
||
| # Проверяем что цифр достаточно | ||
| if len(digits) < 2: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Сдача контрольной работы. Долженко Александра Борисовна
Выполненные задания:
1. Настройка репозитория
2. Функция бинарного поиска (bin_search)
3. Функция проверки контрольной суммы checksum