Overview
This prompt aims to guide users in identifying and fixing bugs in Python scripts. Programmers and developers will benefit by improving their debugging skills and code quality.
Prompt Overview
Purpose: This guide aims to help programmers identify and fix bugs in Python scripts effectively.
Audience: It is designed for developers of all skill levels who want to improve their debugging skills.
Distinctive Feature: The guide emphasizes practical techniques, including the use of print statements and built-in debugging tools.
Outcome: Following this guide will enable users to resolve bugs and enhance their Python coding proficiency.
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Content & Media Creation, Productivity & Workflow
- Techniques: Decomposition, Self-Critique / Reflection, Structured Output
- Models: Claude 3.5 Sonnet, Gemini 2.0 Flash, GPT-4o, Llama 3.1 70B
- Estimated time: 10-20 minutes
- Skill level: Intermediate
Variables to Fill
- [1, 2, 3] – 1, 2, 3
- [n n for m in numbers] – N N For M In Numbers
- [n n for n in numbers] – N N For N In Numbers
- [1, 4, 9] – 1, 4, 9
Example Variables Block
- [n * n for m in numbers]: [1, 4, 9]
- [n * n for n in numbers]: [1, 4, 9]
- [1, 4, 9]: [1, 4, 9]
The Prompt
**Python Bug Fixing Guide**
Given a Python script and a description of its expected functionality, identify and resolve any bugs present in the code to ensure it performs as intended.
## Steps
1. Understand the Bug Description:
– Carefully read the provided information regarding the script’s intended functionality and the issues it is currently facing.
2. Examine the Code:
– Review the provided script to understand its structure, logic, and potential error points.
3. Identify the Bug:
– Look for common issues such as:
– Syntax errors
– Logical mistakes
– Misused functions
– Incorrect data manipulations
4. Debugging Techniques:
– Use print statements to trace variable values and code execution paths.
– Employ Python’s built-in debugging tools such as `pdb`.
– Consider edge cases and test the script with diverse input scenarios.
5. Fix the Bug:
– Modify the code to address the identified issues, ensuring the solution is efficient and maintains overall functionality.
6. Test the Solution:
– Run the script to confirm the bug is fixed.
– Check if it meets the expected outcomes without introducing new errors.
7. Refactor if Necessary:
– Optimize any suboptimal code sections for improved performance or readability while keeping functionality intact.
## Output Format
– Description of the Identified Bug:
– Clearly explain the issue found.
– Revised Code:
– Provide the complete fixed script.
– Explanation of Changes:
– Describe what was modified and why.
– Testing Evidence:
– Present results from testing the fixed code to demonstrate it works as expected.
– Suggestions for Future Improvement:
– Optional recommendations for further enhancements or preventative measures.
## Examples
**Input Script**:
“`python
# A sample input with a simple bug
# Expectation: Calculate the square of each number in the list
numbers = [1, 2, 3]
squares = [n * n for m in numbers] # Bug: wrong variable used
“`
**Expected Outcome**:
– An explanation of the bug
– A corrected script
– Evidence of successful output
**Corrected Script**:
“`python
# Corrected script
numbers = [1, 2, 3]
squares = [n * n for n in numbers]
print(squares) # Output should be [1, 4, 9]
“`
**Explanation**:
– Identified Bug: ‘m’ was incorrectly used in the list comprehension, causing a NameError.
– Correction: Replaced ‘m’ with ‘n’ to fix the variable usage.
– Testing: Successfully calculated squares and confirmed the output is as expected.
## Notes
– Assume the latest Python version unless otherwise specified.
– Consider additional libraries or dependencies if mentioned explicitly in the script.
Screenshot Examples
How to Use This Prompt
- [BUG_DESCRIPTION]: Explanation of the identified issue.
- [REVISED_CODE]: Complete fixed Python script.
- [EXPLANATION_OF_CHANGES]: Description of modifications made.
- [TESTING_EVIDENCE]: Results confirming the fix works.
- [SUGGESTIONS_FOR_IMPROVEMENT]: Recommendations for future enhancements.
- [DEBUGGING_TOOLS]: Tools used for debugging the script.
- [INPUT_SCENARIOS]: Diverse inputs used for testing.
- [OPTIMIZATION]: Improvements made for performance or readability.
Tips for Best Results
- Understand the Bug: Read the bug description thoroughly to grasp the intended functionality of the script.
- Examine the Code: Analyze the script’s structure and logic to pinpoint potential error sources.
- Debugging Techniques: Utilize print statements and Python’s debugging tools like `pdb` to track variable values and execution flow.
- Test the Solution: After fixing the bug, run the script to ensure it meets expected outcomes without introducing new errors.
FAQ
- What is the first step in fixing a Python bug?
Understand the bug description and the intended functionality of the script. - How can you identify common Python bugs?
Look for syntax errors, logical mistakes, misused functions, and incorrect data manipulations. - What debugging techniques can be used in Python?
Use print statements, Python's pdb tool, and test with diverse input scenarios. - What should you do after fixing a bug?
Test the script to confirm the bug is fixed and it meets expected outcomes.
Compliance and Best Practices
- Best Practice: Review AI output for accuracy and relevance before use.
- Privacy: Avoid sharing personal, financial, or confidential data in prompts.
- Platform Policy: Your use of AI tools must comply with their terms and your local laws.
Revision History
- Version 1.0 (February 2026): Initial release.


