From 54acae7c11f4b2b5c7d791dc538731a34cf2e202 Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 15:24:53 +0300 Subject: [PATCH 01/14] Add MIT License --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0ba69bf --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Stanislav Klimovich + +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 928e34e8c394a36d1b8bec7d8c4898aeb27f9029 Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 15:26:25 +0300 Subject: [PATCH 02/14] Add @KubEF in CODEOWNERS --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..707e4bb --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @KubEF @Monrealle From 63a7e73d082cba1d6a80c2b09587fbdcc8fe3a4e Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 15:27:06 +0300 Subject: [PATCH 03/14] Add .gitignore file --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1d74e21 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/ From c16cdbd376cb8539d107f82843041d21cdb3e4de Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 15:30:37 +0300 Subject: [PATCH 04/14] Add .python-version file --- src/.python-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/.python-version diff --git a/src/.python-version b/src/.python-version new file mode 100644 index 0000000..d2e8921 --- /dev/null +++ b/src/.python-version @@ -0,0 +1 @@ +Python 3.12.11 From 90a802b49e2fa5b52d4e7c7fe5d761079d89e650 Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 15:34:28 +0300 Subject: [PATCH 05/14] A README.md file has been added to the program, but it doesn't contain anything yet --- src/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/README.md diff --git a/src/README.md b/src/README.md new file mode 100644 index 0000000..46688f1 --- /dev/null +++ b/src/README.md @@ -0,0 +1 @@ +# Это описание файла From 882168756b827cbe8871112f02f4a6233c74cecc Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 15:47:21 +0300 Subject: [PATCH 06/14] The fast_pow.py file has been fixed and the handling of negative powers and powers of 0 has been added --- src/fast_pow.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/fast_pow.py b/src/fast_pow.py index 1ba1dc1..75b327e 100644 --- a/src/fast_pow.py +++ b/src/fast_pow.py @@ -1,6 +1,14 @@ def fastPow(number, power): - result = number - while power != 1: - result *= result + if power < 0: + print("Степень не может быть отритцательной") + if power == 0: + return 1 + + result = 1 + base = number + while power > 0: + if power % 2 == 1 + result *= base + base *= base power = power // 2 return result From adfa95245ecf2caeaf16f601e48bf3926c1daecb Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 16:01:24 +0300 Subject: [PATCH 07/14] test_fast_pow.py has been modified and new tests have been added (unit tests, edge cases, and a property based test). fast_pow.py has been fixed --- src/fast_pow.py | 2 +- test/test_fast_pow.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/fast_pow.py b/src/fast_pow.py index 75b327e..ba6d0c9 100644 --- a/src/fast_pow.py +++ b/src/fast_pow.py @@ -7,7 +7,7 @@ def fastPow(number, power): result = 1 base = number while power > 0: - if power % 2 == 1 + if power % 2 == 1: result *= base base *= base power = power // 2 diff --git a/test/test_fast_pow.py b/test/test_fast_pow.py index 5e4aebd..8d61145 100644 --- a/test/test_fast_pow.py +++ b/test/test_fast_pow.py @@ -1,9 +1,18 @@ from src.fast_pow import fastPow -def test_two_power_two(): +def test_unit_tests(): # unit тесты assert fastPow(2, 2) == 4 + assert fastPow(1, 10) == 1 + assert fastPow(3, 4) == 81 + assert fastPow(5, 3) == 125 -def test_negative(): +def test_extreme_cases(): # Крайние случаи assert fastPow(-1, 4) == 1 + assert fastPow(0, 10) == 0 + assert fastPow(67, 0) == 1 + assert fastPow(-2, 3) == -8 + +def test_property_based_tests(): # Property based тесты + assert fastPow(7, 4) == 7 ** 4 From e59046bb225dba399f64cdadb29572a2ec45bf96 Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 16:04:54 +0300 Subject: [PATCH 08/14] Add __pycache__ in .gitignore. Add one test in test_fast_pow.py --- .gitignore | 4 ++++ test/test_fast_pow.py | 1 + 2 files changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 1d74e21..7b36579 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ +# VS Code .vscode/ + +# Python +__pycache__/ diff --git a/test/test_fast_pow.py b/test/test_fast_pow.py index 8d61145..0089f85 100644 --- a/test/test_fast_pow.py +++ b/test/test_fast_pow.py @@ -16,3 +16,4 @@ def test_extreme_cases(): # Крайние случаи def test_property_based_tests(): # Property based тесты assert fastPow(7, 4) == 7 ** 4 + assert fastPow(23, 0) == 23 ** 0 From d5e8d7d7c6e5aa004bcd3bbcdc49fa1e59ca6682 Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 16:41:23 +0300 Subject: [PATCH 09/14] Luhn.py has been updated. Comments have been added to the functions and to the code, cardNumber has been changed to number_card, the main() function has been added, and an entry point has been added at the end of the code --- src/luhn.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/luhn.py b/src/luhn.py index 11d993c..d5e41db 100644 --- a/src/luhn.py +++ b/src/luhn.py @@ -1,8 +1,21 @@ -def luhnСheck(cardNumber): - digits = [int(d) for d in str(cardNumber) if d.isdigit()] - control = digits.pop() - parity = (len(digits))%2 +def luhnСheck(number_card): + """ + Проверяет ввод по алгоритму Луна + + Args: + numbee_card: Номер карты в виде строки или числа + Может содержать пробелы и другие символы + Return: + True: Если номер карты корректен + False: Если номер карты неправильный + """ + # Убираем все нецифровые символы + digits = [int(d) for d in str(number_card) if d.isdigit()] + + control = digits.pop() # Контрольная цифра + parity = (len(digits)) % 2 total = 0 + for i in range(len(digits)): if i % 2 == parity: doubled = digits[i] * 2 @@ -11,4 +24,36 @@ def luhnСheck(cardNumber): total += doubled else: total += digits[i] + return (total + control) % 10 == 0 + +def main(): + """Консольная утилита на основе алгоритма Луна для проверки номеров карт""" + print("Введите номер карты или -1 для выхода:) + + while True: + try: + user_input = input("> ").strip() + + # Проверяем ввод на наличие -1 + if user_input == '-1': + print("Выход из программы") + break + + # Проверяем, что ввод не пустой + if not user_input: + print("Ошибка, введите номер карты) + continue + # Проверяем номер карты + if luhnСheck(user_input): + print("Correct") + + else: + print("Incorrect") + + except KeyboardInterrupt: + print("\nВыход из программы") + break + +if __name__ == "__main__": + main() From e5a3cc67523b8c5c8155386425d1ca588e80b19d Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 16:42:40 +0300 Subject: [PATCH 10/14] Little fix luhn.py (Added a pick in print) --- src/luhn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/luhn.py b/src/luhn.py index d5e41db..b3b684b 100644 --- a/src/luhn.py +++ b/src/luhn.py @@ -29,7 +29,7 @@ def luhnСheck(number_card): def main(): """Консольная утилита на основе алгоритма Луна для проверки номеров карт""" - print("Введите номер карты или -1 для выхода:) + print("Введите номер карты или -1 для выхода:") while True: try: From c64812b7c7b1f4837dd1358f50ce4940acd7021e Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 16:43:30 +0300 Subject: [PATCH 11/14] Little fix luhn.py (Added a pick in print) --- src/luhn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/luhn.py b/src/luhn.py index b3b684b..75176e4 100644 --- a/src/luhn.py +++ b/src/luhn.py @@ -42,7 +42,7 @@ def main(): # Проверяем, что ввод не пустой if not user_input: - print("Ошибка, введите номер карты) + print("Ошибка, введите номер карты") continue # Проверяем номер карты if luhnСheck(user_input): From f46eca7a6463a6a1074d0ff5097c6393525c26ef Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 16:49:22 +0300 Subject: [PATCH 12/14] The luchCheck function has been renamed to the more pleasant luchn_check (luhn.py) --- src/luhn.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/luhn.py b/src/luhn.py index 75176e4..2c7eee7 100644 --- a/src/luhn.py +++ b/src/luhn.py @@ -1,4 +1,4 @@ -def luhnСheck(number_card): +def luhn_check(number_card): """ Проверяет ввод по алгоритму Луна @@ -45,7 +45,7 @@ def main(): print("Ошибка, введите номер карты") continue # Проверяем номер карты - if luhnСheck(user_input): + if luhn_check(user_input): print("Correct") else: From 86f3fa9f98165cb114fd3072fb6b40f1d9cb6289 Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 16:52:41 +0300 Subject: [PATCH 13/14] fast_pow.py and luhn.py Translated to the pep8 standard (using autopep8) --- src/luhn.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/luhn.py b/src/luhn.py index 2c7eee7..0c1d947 100644 --- a/src/luhn.py +++ b/src/luhn.py @@ -12,7 +12,7 @@ def luhn_check(number_card): # Убираем все нецифровые символы digits = [int(d) for d in str(number_card) if d.isdigit()] - control = digits.pop() # Контрольная цифра + control = digits.pop() # Контрольная цифра parity = (len(digits)) % 2 total = 0 @@ -27,6 +27,7 @@ def luhn_check(number_card): return (total + control) % 10 == 0 + def main(): """Консольная утилита на основе алгоритма Луна для проверки номеров карт""" print("Введите номер карты или -1 для выхода:") @@ -55,5 +56,6 @@ def main(): print("\nВыход из программы") break + if __name__ == "__main__": main() From 8923029fd000d0317ab2375dd02fa46c6fb8d597 Mon Sep 17 00:00:00 2001 From: Stanislav Klimovich Date: Mon, 27 Oct 2025 16:54:41 +0300 Subject: [PATCH 14/14] =?UTF-8?q?=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=B2=20luhn=5Fcheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_luhn.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/test_luhn.py b/test/test_luhn.py index 1c021a2..c605c10 100644 --- a/test/test_luhn.py +++ b/test/test_luhn.py @@ -1,9 +1,8 @@ -from src.luhn import luhnСheck +from src.luhn import luhn_check def test_good(): - assert luhnСheck("8571 2612 1234 5467") - + assert luhn_check("8571 2612 1234 5467") def test_bad(): - assert not luhnСheck("4561 2612 1234 5463") \ No newline at end of file + assert not luhn_check("4561 2612 1234 5463")