Skip to content

Comments

Теврюков Илья Андреевич Б42#4

Open
Quark1111 wants to merge 1 commit intopython-course-matmex:mainfrom
Quark1111:main
Open

Теврюков Илья Андреевич Б42#4
Quark1111 wants to merge 1 commit intopython-course-matmex:mainfrom
Quark1111:main

Conversation

@Quark1111
Copy link

No description provided.

…ht'. Added comprehensive test suite for binary search. Implemented ISBN validator utility. Fixed weight calculation from 'weight = 10' to 'weight = 10 - i'. Added necessary input validation and error handling. Extended test coverage for all components.
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.

ISBN10: 3/10
Бинарный поиск: 2/5
Оформление кода: 3/10 (snake_case, лицензия, описание PR, .gitignore, нет обработки ошибок)

right = mid - 1
return -1
def binSearch(xs: list[int], x: int):
xs = sorted(xs)
Copy link

Choose a reason for hiding this comment

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

Бинарный поиск должен работать за $O(\log{N})$, добавляя сортировку он начинает работать за $O(N)$.

checksum = total + checkDigit
return checksum % 11 == 0
def modulo11Checksum(ISBNNumber: str):
digits = [int(char) for char in ISBNNumber if char.isdigit()]
Copy link

Choose a reason for hiding this comment

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

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

def modulo11Checksum(ISBNNumber: str):
digits = [int(char) for char in ISBNNumber if char.isdigit()]
if len(digits) != 10:
return -1
Copy link

Choose a reason for hiding this comment

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

Вы в одном месте возвращаете -1, а в другом bool. В Python -1 оценивается как True в булевом контексте.



def test_good_with_x_check_digit():
assert modulo11Checksum("0-304-33376-")
Copy link

Choose a reason for hiding this comment

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

modulo11Checksum выкинет дефисы, получит 9 цифр, вернет -1, а assert сработает как True и тест пройдет.

Comment on lines +14 to +25
ISBNNumber = input()

while ISBNNumber != '-1':
res = modulo11Checksum(ISBNNumber)
if res == 1:
print('correct')
elif res == -1:
print('Incorrect number length')
else:
print('incorrect')
ISBNNumber = input()

Copy link

Choose a reason for hiding this comment

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

Когда pytest импортирует этот файл для тестов, он зависнет, ожидая ввода данных.
Код, который относится к запуску нужно оборачивать в if __name__ == "__main__".

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