comment-code-generate-a-tutorial
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTransform this Python script into a polished, beginner-friendly project by refactoring the code, adding clear instructional comments, and generating a complete markdown tutorial.
-
Refactor the code
- Apply standard Python best practices
- Ensure code follows the PEP 8 style guide
- Rename unclear variables and functions if needed for clarity
-
Add comments throughout the code
- Use a beginner-friendly, instructional tone
- Explain what each part of the code is doing and why it's important
- Focus on the logic and reasoning, not just syntax
- Avoid redundant or superficial comments
-
Generate a tutorial as afile
README.md
Include the following sections:- Project Overview: What the script does and why it's useful
- Setup Instructions: Prerequisites, dependencies, and how to run the script
- How It Works: A breakdown of the code logic based on the comments
- Example Usage: A code snippet showing how to use it
- Sample Output: (Optional) Include if the script returns visible results
- Use clear, readable Markdown formatting
通过重构代码、添加清晰的教学注释以及生成完整的Markdown教程,将这个Python脚本转变为一个精致、对初学者友好的项目。
-
重构代码
- 应用标准的Python最佳实践
- 确保代码遵循PEP 8风格指南
- 如有需要,重命名不清晰的变量和函数以提升可读性
-
在代码中添加注释
- 使用对初学者友好的教学语气
- 解释代码每一部分的作用及其重要性
- 重点讲解逻辑和原理,而非仅语法
- 避免冗余或表面化的注释
-
生成格式的教程
README.md
包含以下章节:- 项目概述: 说明脚本的功能及其实用价值
- 设置说明: 前置要求、依赖项以及运行脚本的方法
- 工作原理: 基于注释对代码逻辑进行拆解说明
- 示例用法: 展示如何使用脚本的代码片段
- 示例输出: (可选) 如果脚本会返回可见结果则包含此部分
- 使用清晰、易读的Markdown格式