Skip to content

Comments

Dolzhenko kr 1 python #14

Open
DolzhenkoAlexa wants to merge 7 commits intopython-course-matmex:mainfrom
DolzhenkoAlexa:Dolzhenko_KR-1_python
Open

Dolzhenko kr 1 python #14
DolzhenkoAlexa wants to merge 7 commits intopython-course-matmex:mainfrom
DolzhenkoAlexa:Dolzhenko_KR-1_python

Conversation

@DolzhenkoAlexa
Copy link

Сдача контрольной работы. Долженко Александра Борисовна

Выполненные задания:

1. Настройка репозитория

  • Добавлен MIT License
  • Добавлен .gitignore для Python
  • Настроен Ruff и пройдено CL

2. Функция бинарного поиска (bin_search)

  • Исправлен алгоритм бинарного поиска
  • Исправлены баги: условие цикла, обработка пустого списка
  • Добавлены тесты для исправ случаев

3. Функция проверки контрольной суммы checksum

  • Реализован алгоритм проверки ISBN-10
  • Исправлены баги: алгоритм весов, обработка ошибок ввода
  • Добавлены тесты для исправ случаев

Copy link

@Godrik0 Godrik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISBN: 5/10
Бинарный поиск: 5/5
Оформление: 10/10

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В задании требовалось также реализовать консольную утилиту.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У Вас пропущена обработка символа X, который может служить контрольной цифрой.

Comment on lines +23 to +24
checksum = total % 11
return checksum == check_digit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ошибка в логике.
Нужно было либо оставить checksum = total + checkDigit и сравнивать остаток от деления на 11 с 0.
Либо высчитывать вот так (11 - (sum % 11)) % 11 и тогда уже сравнивать с контрольной цифрой.

digits = [int(char) for char in isbn_number if char.isdigit()]

# Проверяем что цифр достаточно
if len(digits) < 2:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему <2 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants