Best ChatGPT Prompt for Coding

Write, debug, and understand code faster — works for any programming language.

The Prompt
You are a senior software engineer with 15 years of experience. Help me with a coding task.

Language: [Python / JavaScript / Java / C++ / etc.]
Framework (if any): [React / Django / Node.js / etc.]
What I'm trying to do: [DESCRIBE THE GOAL IN PLAIN ENGLISH]
My current code (if any):
```
[PASTE YOUR CODE HERE]
```
The problem: [what's not working, or what you need built from scratch]
My skill level: [beginner / intermediate / advanced]

Requirements:
- Write clean, production-ready code (not just a quick hack)
- Add brief comments explaining non-obvious logic
- If there's an error, explain WHY it happened, not just the fix
- If there are multiple approaches, tell me which one you'd use and why
- Include example usage showing how to run/test the code
- Follow best practices for the language (naming conventions, error handling, etc.)

How to Use This Prompt

  1. Copy the prompt and fill in your language and task
  2. Always paste your current code if you have any — the AI needs context
  3. Describe the problem in plain English first, then show the error message if there is one
  4. Paste into ChatGPT or Claude
  5. Test the code it gives you, then come back with: "It works but now I need it to also [next feature]"

The more context you give (error messages, expected vs actual output, what you've tried), the better the answer.

Example Output

Task: Python script to scrape product prices from a webpage

Response:

import requests
from bs4 import BeautifulSoup

def get_product_prices(url):
    """Fetch and parse product prices from a webpage."""
    response = requests.get(url, headers={
        'User-Agent': 'Mozilla/5.0'  # Avoid being blocked
    })
    response.raise_for_status()

    soup = BeautifulSoup(response.text, 'html.parser')
    products = []

    for item in soup.select('.product-card'):
        name = item.select_one('.product-title')
        price = item.select_one('.product-price')
        if name and price:
            products.append({
                'name': name.text.strip(),
                'price': price.text.strip()
            })

    return products

Tips to Get Better Results

  • Include error messages. "It doesn't work" gets a bad answer. "I get TypeError: cannot unpack non-iterable NoneType object on line 14" gets a great one.
  • Ask for explanations. After getting code, say "Walk me through this line by line" if you want to learn, not just copy.
  • Request tests. Say "Write unit tests for this function" — catching bugs early saves hours.
  • Iterate. Build features one at a time. Get the basic version working, then say "Now add error handling" or "Now make it handle edge cases."

Best AI Tools for This

ChatGPT AI Books on Amazon Claude

Related Prompts