From 0fd5aa00a547804d4d2a5e86b1689afdb39e048b Mon Sep 17 00:00:00 2001 From: Barinov Gosha Date: Fri, 7 Nov 2025 16:21:48 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=B0=D0=BB=D0=B3=D0=BE=D1=80=D0=B8=D1=82?= =?UTF-8?q?=D0=BC=20=D0=BD=D0=B5=20=D0=BD=D0=B0=D1=85=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8=D0=B5=20=D1=8D=D0=BB?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D0=BD=D1=82=D1=8B=20=D0=B8=20=D1=8F=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=8D=D1=82=D0=BE?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D1=8F=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BB=D1=83=D1=87=D0=B8=D0=B9=20=D0=BA=D0=BE=D0=B3=D0=B4=D0=B0?= =?UTF-8?q?=20left=20=3D=3D=20right?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin_search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin_search.py b/src/bin_search.py index 713abfc..3c91f7d 100644 --- a/src/bin_search.py +++ b/src/bin_search.py @@ -1,6 +1,6 @@ def binSearch(xs: list[int], x: int): left, right = 0, len(xs) - 1 - while left < right: + while left <= right: mid = (left + right) // 2 if xs[mid] == x: return mid From 4b5c354dc31f0ed9810abcee130ca38832a5fc1b Mon Sep 17 00:00:00 2001 From: Barinov Gosha Date: Fri, 7 Nov 2025 16:28:04 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=B2=20=D0=B1=D0=B8=D0=BD=D0=B0=D1=80?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=20=D0=BF=D0=BE=D0=B8=D1=81=D0=BA=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=B3?= =?UTF-8?q?=D0=B4=D0=B0=20=D1=85=20=D0=BD=D0=B5=20=D1=86=D0=B5=D0=BB=D0=BE?= =?UTF-8?q?=D0=B5=20=D1=87=D0=B8=D1=81=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin_search.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bin_search.py b/src/bin_search.py index 3c91f7d..1d677f0 100644 --- a/src/bin_search.py +++ b/src/bin_search.py @@ -1,5 +1,7 @@ def binSearch(xs: list[int], x: int): left, right = 0, len(xs) - 1 + if not isinstance(x, int): + raise TypeError(f'X must be int, but {type(x)}') while left <= right: mid = (left + right) // 2 if xs[mid] == x: From 5112bfd8310c24e8d1c1b21dbcfbec2339fb855b Mon Sep 17 00:00:00 2001 From: Barinov Gosha Date: Fri, 7 Nov 2025 16:35:31 +0300 Subject: [PATCH 3/4] add gitignore file --- .gitignore | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cb5b410 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +### 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 +.clang-format \ No newline at end of file From 362f4e584a2299d90975472e8e6ad1c2fb042037 Mon Sep 17 00:00:00 2001 From: Barinov Gosha Date: Fri, 7 Nov 2025 16:59:50 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=20=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D1=83=D1=8E=20=D1=83=D1=82=D0=B8=D0=BB=D0=B8=D1=82=D1=83?= =?UTF-8?q?=20=D0=B8=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BA=20=D0=BD=D0=B5=D0=B9=20?= =?UTF-8?q?1)=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82=D0=BD=D1=8B=D0=B9=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82(=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=D1=82=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D1=82=20=D1=82?= =?UTF-8?q?=D1=80=D1=83=20=D0=BA=D0=BE=D0=B3=D0=B4=D0=B0=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D1=8B=20correct)=202)=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=20=D0=BA=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D1=8B=D0=B9=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=8F=D0=B5=D1=82=20=D1=87=D1=82=D0=BE=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D0=BB=D0=B5=D0=B4=D0=BD=D0=B5=D0=B5=20=D1=87=D0=B8=D1=81=D0=BB?= =?UTF-8?q?=D0=BE=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82=20=D0=B1=D1=8B=D1=82?= =?UTF-8?q?=D1=8C=2010?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checksum.py | 30 ++++++++++++++++++++++-------- test/test_checksum.py | 6 +++++- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/checksum.py b/src/checksum.py index 74b4fb0..35bfeb6 100644 --- a/src/checksum.py +++ b/src/checksum.py @@ -1,14 +1,28 @@ def modulo11Checksum(ISBNNumber: str): - digits = [int(char) for char in ISBNNumber if char.isdigit()] - - checkDigit = digits[-1] - + if ISBNNumber[-1] == 'x' or ISBNNumber[-1] == 'X': + digits += [10] total = 0 - for i in range(len(digits) - 1): - weight = 10 + if len(digits) != 10: + print("incorrect input, should be 10 numbers") + return False + for i in range(10): + weight = 10 - i digit = digits[i] total += digit * weight + if total % 11 == 0: + print("correct") + return True + else: + print("incorrect") + return False + +isbnnum = input('input your number: ') +while isbnnum != '-1': + modulo11Checksum(isbnnum) + isbnnum = input('input your number: ') + + + + - checksum = total + checkDigit - return checksum % 11 == 0 diff --git a/test/test_checksum.py b/test/test_checksum.py index f64a64c..d41e053 100644 --- a/test/test_checksum.py +++ b/test/test_checksum.py @@ -2,8 +2,12 @@ def test_good(): - assert modulo11Checksum("2-266-11156-8") + assert modulo11Checksum("2-266-11156-6") def test_bad(): assert not modulo11Checksum("2-266-11156-3") + +def test_with_x(): + assert modulo11Checksum("156-881-111-x") +