Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
name: Ruff
on: [push, pull_request]
on: push
jobs:
ruff:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
# Update output format to enable automatic inline annotations.
- name: Run Ruff
run: ruff check --output-format=github .
207 changes: 207 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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__/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Andrew-Kochanov

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.
26 changes: 5 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# Контрольная работа 1 (1 вариант)

Темы: Git и GitHub, стандарты оформления кода, хорошие практики, тестирование.

## Этапы выполнения работы

- Сделать **fork** этого репозитория
- Добавить недостающие файлы для "хорошо оформленного" репозитория
- Исправить ошибки, из-за которых не проходит CI
- Найти и исправить баг(и), которые есть в `src/fast_pow.py` и `src/luhn.py`
- Добавить исключения в соответствующих случаях (например, когда степень в `fast_pow` отрицательная)
- Исправить и/или дополнить тесты так, чтобы они покрывали найденные ошибки
- Для каждого бага должен быть отдельный **commit** с его исправлением, в его описании должно быть пояснение (можно на русском) решённой проблемы
- На основе [алгоритма Луна](https://ru.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC_%D0%9B%D1%83%D0%BD%D0%B0) реализовать простую консольную утилиту
- Пользователь вводит в консоль номер карточки $\to$ ему выводится "correct" или "incorrect" в зависимости от правильности номера
- Выход из утилиты происходит по вводу пользователем `-1`
- Ошибки не должны прерывать прерывать работу утилиты, но пользователь должен быть уведомлен о том, что он сделал что-то не так
- Реализация утилиты должна быть в модуле `src/luhn.py`
- Сделать **pull request** (один на обе задачи) с решением в main ветку этого репозитория
- **pull request** должен содержать описание проделанной работы, ваше ФИО и номер группы
- Если не получилось/забыли сделать адекватное описание исправленных ошибок в описании к **commit**, то нужно сделать это хотя бы в комментариях к **pull request**
Контрольная работа №1 по Python;
Кочанов Андрей;
Python 3.13.7;
tg @chempufcfor;
st142099@student.spbu.ru
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

[tool.pytest.ini_options]
testpaths = "test"
pythonpath = '.'
pythonpath = '.'
7 changes: 5 additions & 2 deletions src/fast_pow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
def fastPow(number, power):
result = number
while power != 1:
result *= result
power = power // 2
result *= number
power = power - 1
print(result, power)
return result


22 changes: 22 additions & 0 deletions src/luhn.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Стоило позапускать свою утилиту, тогда бы вы отловили абсолютное большинство из указанных недостатков

Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,25 @@ def luhnСheck(cardNumber):
else:
total += digits[i]
return (total + control) % 10 == 0


def utility(cardNumber):
cardNumber = input('Введите номер карты(или -1, чтобы выйти)')
Comment on lines +17 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

А что надо передавать в качестве аргумента? Зачем он, если я сразу перезаписываю его?

flag = False
while cardNumber != "-1":
if flag:
Copy link
Contributor

Choose a reason for hiding this comment

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

Ваш флаг один раз за жизнь программы может поменяться на True, а все последующие попытки ввести номер карты будут считаться неправильными...

print("Вы неправильно ввели номер карты, будте внимательны")
Copy link
Contributor

Choose a reason for hiding this comment

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

Как полтзователь, что именно я неправильно ввёл? Мне бы хотелось понимать

cardNumber = input('Введите номер карты(или -1, чтобы выйти):')
for i in range(len(cardNumber)):
if i % 4 == 0:
if cardNumber != " ":
flag = True
Comment on lines +25 to +27
Copy link
Contributor

Choose a reason for hiding this comment

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

То есть если я не разделил номер карты пробелами, то я сразу неправ? Это неочевидно. В любом случаче, это условие ещё и неправильное. Я должен начинать с пробела (0 % 4 == 0)? И если так, то на позиции с индексом 4 стоит уже какая-то цифра

else:
if cardNumber[i] not in '1234567890':
flag = True
if not flag:
if luhnСheck(cardNumber):
print("Correct")
else:
print("Incorect")
cardNumber = input('Введите номер карты(или -1, чтобы выйти):')