-
Notifications
You must be signed in to change notification settings - Fork 22
control work #5
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
base: main
Are you sure you want to change the base?
control work #5
Changes from all commits
b9cf3ec
6ab38ed
a0e8ef7
fc21f5a
8c7f076
efb689c
c59a402
3e9bf43
caee695
0ca7f90
d192d23
800bd43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,28 @@ | ||
| def modulo11Checksum(ISBNNumber: str): | ||
| def modulo11_checksum(is_bn_number: str): | ||
|
|
||
| digits = [int(char) for char in ISBNNumber if char.isdigit()] | ||
| if not isbn_number or not isinstance(isbn_number, str): | ||
| raise ValueError("Invalid input: must be non-empty string") | ||
|
|
||
|
|
||
| checkDigit = digits[-1] | ||
| digits = [int(char) for char in is_bn_number if char.isdigit()] | ||
|
|
||
| check_digit = digits[-1] | ||
|
|
||
| total = 0 | ||
| for i in range(len(digits) - 1): | ||
| weight = 10 | ||
| weight = 10 - i | ||
| digit = digits[i] | ||
| total += digit * weight | ||
|
Comment on lines
+7
to
15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. У Вас пропущена обработка символа |
||
|
|
||
| checksum = total + checkDigit | ||
| return checksum % 11 == 0 | ||
| checksum = total % 11 | ||
| return checksum == check_digit | ||
|
Comment on lines
+17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ошибка в логике. |
||
|
|
||
|
|
||
| while True: | ||
| isbn = input("ISBN: ").strip() | ||
| if isbn == "-1": | ||
| break | ||
| if check_isbn(isbn): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. У Вас функция называется |
||
| print("correct") | ||
| else: | ||
| print("incorrect") | ||
|
Comment on lines
+21
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Когда
Comment on lines
+21
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Нужен блок try-except, который при ошибке уведомлял бы пользователя о сбое в работе, но программа при этом не падала. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,21 @@ | ||
| 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], 3) == 2 | ||
|
|
||
|
|
||
| def test_start(): | ||
| assert binSearch([1, 2, 3, 4], 2) == 1 | ||
| assert bin_search([1, 2, 3, 4], 1) == 0 | ||
| assert bin_search([1, 2, 3, 4], 2) == 1 | ||
|
|
||
|
|
||
| def test_end(): | ||
| assert bin_search([1, 2, 3, 4, 5], 5) == 4 | ||
| assert bin_search([1, 2, 3, 4], 4) == 3 | ||
|
|
||
|
|
||
| def test_not_in_list(): | ||
| assert binSearch([1, 2, 3, 4], 5) == -1 | ||
| assert bin_search([1, 2, 3, 4], 5) == -1 | ||
| assert bin_search([1, 2, 3, 4], 0) == -1 | ||
| assert bin_search([1, 2, 3, 4], 6) == -1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,20 @@ | ||
| from src.checksum import modulo11Checksum | ||
| from src.checksum import modulo11_checksum | ||
|
|
||
| def test_valid_isbn10_with_hyphens(): | ||
| #Тесты с дефисами | ||
| assert modulo11_checksum("2-266-11156-8") | ||
| assert modulo11_checksum("0-7475-3269-9") | ||
| assert modulo11_checksum("1-56619-909-3") | ||
|
|
||
| def test_good(): | ||
| assert modulo11Checksum("2-266-11156-8") | ||
|
|
||
| def test_valid_isbn10_without_hyphens(): | ||
| #Тест без дефисов | ||
| assert modulo11_checksum("2266111568") | ||
| assert modulo11_checksum("0747532699") | ||
| assert modulo11_checksum("1566199093") | ||
|
|
||
| def test_bad(): | ||
| assert not modulo11Checksum("2-266-11156-3") | ||
| def test_invalid_isbn10(): | ||
| #Тесты невалидности | ||
| assert not modulo11_checksum("2-266-11156-3") | ||
| assert not modulo11_checksum("0-7475-3269-8") | ||
| assert not modulo11_checksum("1566199095") |
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.
Ошибка в
isbn_number, в функции аргумент называлсяis_bn_number.