欢迎来到 Python 训练营的基础部分!本项目旨在通过一系列实践练习,帮助你巩固 Python 编程的基础知识。
你需要通过补全 exercises 目录下的 Python 代码,并通过运行提供的测试来验证你的实现。
exercises/hello_world.py: print 输出语句。exercises/data_types.py: 变量和基本数据类型 (整数, 浮点数, 字符串等)。exercises/if_else.py: if-elif-else 条件语句。exercises/for_loop.py: for 循环。exercises/while_loop.py: while 循环。exercises/break_continue.py: break 和 continue 语句。exercises/function_params.py: 函数定义和参数传递。exercises/math_module.py: 使用 math 模块进行计算。exercises/list_operations.py: 列表常用操作。exercises/dict_operations.py: 字典常用操作。exercises/set_operations.py: 集合常用操作。exercises/string_formatting.py: 字符串格式化 (f-strings)。exercises/string_split.py: 字符串分割 (split 方法)。exercises/regex_match.py: 正则表达式基础匹配。exercises/file_operations.py: 文件读写基础。exercises/http_requests.py: 发送 HTTP 请求和处理响应。exercises/oop_basics.py: 类和对象的基础。请按照以下步骤完成练习:
1. 准备 GitHub 仓库
git clone https://github.com/YOUR_USERNAME/Python-Training-Camp-Basic.git
cd Python-Training-Camp-Basic
(请将 YOUR_USERNAME 替换为你的 GitHub 用户名)2. 设置本地开发环境
python -m venv .venv
source .venv/bin/activate.venv\Scripts\activate主要依赖包括pip install -r requirements.txt
pytest, flake8, pytest-cov, requests。3. 完成练习
exercises/ 目录,根据 建议学习顺序 或你感兴趣的主题选择一个 .py 文件。# TODO: 或 # 请在下方编写代码 的地方编写你的 Python 代码。4. 本地测试 (可选但推荐)
# 运行所有测试
python -m pytest tests/ -v
# 运行单个练习的测试 (例如 if_else.py)
python -m pytest tests/test_if_else.py -v
PASSED/FAILED) 调试代码。5. 提交代码与自动评分
git add exercises/your_modified_file.py
git commit -m "完成 if_else.py 练习"
git push origin main
(修改 your_modified_file.py 和提交信息)建议按照练习文件的编号顺序进行:
# 确保已安装依赖
# pip install -r requirements.txt
# 运行所有测试
python -m pytest tests/ -v
# 运行特定测试文件
python -m pytest tests/test_if_else.py -v
GitHub Actions 会自动进行评分:
tests/ 目录下的所有测试用例全部通过。tests/ 目录下至少有一个测试用例失败。Python-Training-camp/ ├── exercises/ # 练习题目 │ ├── hello_world.py │ ├── data_types.py │ ├── if_else.py │ ├── for_loop.py │ ├── while_loop.py │ ├── ... │ ├── string_formatting.py │ ├── string_split.py │ ├── regex_match.py │ ├── file_operations.py │ ├── http_requests.py │ └── oop_basics.py ├── tests/ # 测试文件 │ ├── test_hello_world.py │ ├── test_data_types.py │ ├── ... │ ├── test_string_split.py │ ├── test_regex_match.py │ ├── test_file_operations.py │ ├── test_http_requests.py │ └── test_oop_basics.py └── requirements.txt # 项目依赖