From 18b5ba4ca7ec2e04f50c9ac3b6f3523535e8da49 Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 16:03:14 +0300 Subject: [PATCH 01/10] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..db6ff11 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Daria + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 96593c942fe0027c24f54a9abdff95e12d2f3c1a Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 16:06:42 +0300 Subject: [PATCH 02/10] Create .gitignore --- .gitignore | 207 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7faf40 --- /dev/null +++ b/.gitignore @@ -0,0 +1,207 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[codz] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py.cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock +#poetry.toml + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python. +# https://pdm-project.org/en/latest/usage/project/#working-with-version-control +#pdm.lock +#pdm.toml +.pdm-python +.pdm-build/ + +# pixi +# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control. +#pixi.lock +# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one +# in the .venv directory. It is recommended not to include this directory in version control. +.pixi + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.envrc +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Abstra +# Abstra is an AI-powered process automation framework. +# Ignore directories containing user credentials, local state, and settings. +# Learn more at https://abstra.io/docs +.abstra/ + +# Visual Studio Code +# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore +# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore +# and can be added to the global gitignore or merged into this file. However, if you prefer, +# you could uncomment the following to ignore the entire vscode folder +# .vscode/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc + +# Cursor +# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to +# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data +# refer to https://docs.cursor.com/context/ignore-files +.cursorignore +.cursorindexingignore + +# Marimo +marimo/_static/ +marimo/_lsp/ +__marimo__/ From 6a4961bedaffa1b97ad6e7ae06dcdaeb3a26cf4b Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 16:09:04 +0300 Subject: [PATCH 03/10] Create .python-version --- .python-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .python-version diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..4e0cbc8 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +Python 3.12.3 From 4a64f5af41a55a7ff9fb3fdbf4a02d3bbcf994fd Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 16:44:32 +0300 Subject: [PATCH 04/10] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20checksum.py,=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=8F=D0=B5=D0=BC=20=D0=B2=D1=81=D0=B5=20=D1=81=D0=B8?= =?UTF-8?q?=D0=BC=D0=B2=D0=BE=D0=BB=D1=8B=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= =?UTF-8?q?=D0=B8,=20=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B0=D1=8F=20X,=20?= =?UTF-8?q?=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D0=BE=D0=B1=D0=BE?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=87=D0=B0=D0=B5=D1=82=2010.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checksum.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/checksum.py b/src/checksum.py index 74b4fb0..745795e 100644 --- a/src/checksum.py +++ b/src/checksum.py @@ -1,6 +1,11 @@ def modulo11Checksum(ISBNNumber: str): - digits = [int(char) for char in ISBNNumber if char.isdigit()] + digits = [] + for char in ISBNNumber: + if char.isdigit(): + digits.append(int(char)) + elif char.upper() == 'X': + digits.append(10) checkDigit = digits[-1] From 9ec6a1b000505d190a50fb80ae795d343854246f Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 16:45:57 +0300 Subject: [PATCH 05/10] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20checksum.py,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=D0=B8=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2=D0=B8=D0=B5?= =?UTF-8?q?,=20=D1=87=D1=82=D0=BE=20ISBN-10=20=D0=B4=D0=BE=D0=BB=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B8=D0=BC=D0=B5=D1=82=D1=8C=2010=20=D1=86?= =?UTF-8?q?=D0=B8=D1=84=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checksum.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/checksum.py b/src/checksum.py index 745795e..dd1c71a 100644 --- a/src/checksum.py +++ b/src/checksum.py @@ -7,6 +7,9 @@ def modulo11Checksum(ISBNNumber: str): elif char.upper() == 'X': digits.append(10) + if len(digits) != 10: + return False + checkDigit = digits[-1] total = 0 From ef336d11e642e03def221bd244722255ab12a4f7 Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 16:48:05 +0300 Subject: [PATCH 06/10] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20checksum.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Вес каждого элемента теперь убывает, а последний элемент умножается на свой вес. --- src/checksum.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/checksum.py b/src/checksum.py index dd1c71a..a07a400 100644 --- a/src/checksum.py +++ b/src/checksum.py @@ -14,9 +14,9 @@ def modulo11Checksum(ISBNNumber: str): total = 0 for i in range(len(digits) - 1): - weight = 10 + weight = 10 - i digit = digits[i] total += digit * weight - checksum = total + checkDigit + checksum = total + checkDigit * (weight - 1) return checksum % 11 == 0 From 306c7d542766fdd2d648778b6d4a94d2db05c18a Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 16:51:30 +0300 Subject: [PATCH 07/10] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20bin=5Fsearch.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Теперь мы учитываем случай, когда left == right. --- 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 d9a7e305c4dc95a998f7a336301b24e0050fb4b8 Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 17:03:23 +0300 Subject: [PATCH 08/10] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20test=5Fchecksum.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавили хорошую проверку с Х и плохую проверку с 9 цифрами --- test/test_checksum.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/test_checksum.py b/test/test_checksum.py index f64a64c..d1bce1d 100644 --- a/test/test_checksum.py +++ b/test/test_checksum.py @@ -3,7 +3,12 @@ def test_good(): assert modulo11Checksum("2-266-11156-8") - + +def test_good2(): + assert modulo11Checksum("2-22X-11156-8") def test_bad(): assert not modulo11Checksum("2-266-11156-3") + +def test_bad2(): + assert not modulo11Checksum("2-266-1156-3") From 0ec79b1d7b705d7ccb6ed790fabb0c7e564021ea Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 17:28:38 +0300 Subject: [PATCH 09/10] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=20checksum.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Вводим номер и проверяем на корректность. --- src/checksum.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/checksum.py b/src/checksum.py index a07a400..6f07b67 100644 --- a/src/checksum.py +++ b/src/checksum.py @@ -20,3 +20,12 @@ def modulo11Checksum(ISBNNumber: str): checksum = total + checkDigit * (weight - 1) return checksum % 11 == 0 + +ISBNNumber = input("Введите исбн номер: ") +while ISBNNumber != "-1": + result = modulo11Checksum(ISBNNumber) + if result == 1: + print("correct") + else: + print("incorrect") + ISBNNumber = input("Введите исбн номер: ") From 94cc57635f7f54499d7f4cf7e2bbfeb890019748 Mon Sep 17 00:00:00 2001 From: Daria Date: Fri, 7 Nov 2025 17:35:19 +0300 Subject: [PATCH 10/10] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=D0=B8=20checksum.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавили в функции проверку на правильность формата номера. --- src/checksum.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/checksum.py b/src/checksum.py index 6f07b67..090de6e 100644 --- a/src/checksum.py +++ b/src/checksum.py @@ -1,11 +1,13 @@ def modulo11Checksum(ISBNNumber: str): digits = [] - for char in ISBNNumber: - if char.isdigit(): - digits.append(int(char)) - elif char.upper() == 'X': - digits.append(10) + if len(ISBNNumber) == 13 and ISBNNumber.count('-') == 3: + if ISBNNumber[1] == '-' and ISBNNumber[-2] == '-': + for char in ISBNNumber: + if char.isdigit(): + digits.append(int(char)) + elif char.upper() == 'X': + digits.append(10) if len(digits) != 10: return False