Games & code · The What2Prompt engine

Python prompt generator: code with clear tests

Working Python starts with a clear input, an expected output and an environment you can reproduce. Use the What2Prompt engine to brief a coding AI on a small task, then review and test its answer rather than assuming a plausible-looking script is correct.

See all prompt guides →
2Which AI will you paste it into?
Short and punchy.
1 credit per prompt

Works with ChatGPT, Claude, Gemini, Midjourney, Suno and more.

Copy · Paste · Done
STEP 3 · YOUR PROMPT
Prompt for Claude CodeQuickExample

Role

You are a Python developer.

Context

Use the stated Python version, actual inputs and permitted dependencies.

Task

Write a Python 3.12 command-line script using only the standard library.
Read a UTF-8 CSV with columns date, category and amount; validate each amount with decimal.Decimal and summarize totals by category into a new CSV.

Format

Include argparse usage, helpful errors with row numbers and unittest cases for empty input, missing columns and invalid amounts.
Show a tiny sample input and its exact expected output.

Guardrails

Do not modify the input file or overwrite an existing output.
5 free prompts

Example prompts

Example

Organize a CSV safely

Role

You are a Python developer.

Context

Use the stated Python version, actual inputs and permitted dependencies.

Task

Write a Python 3.12 command-line script using only the standard library.
Read a UTF-8 CSV with columns date, category and amount; validate each amount with decimal.Decimal and summarize totals by category into a new CSV.

Format

Include argparse usage, helpful errors with row numbers and unittest cases for empty input, missing columns and invalid amounts.
Show a tiny sample input and its exact expected output.

Guardrails

Do not modify the input file or overwrite an existing output.
Example

Debug with evidence

Role

Python developer.

Context

Use the stated Python version, actual inputs and permitted dependencies.

Task

Investigate the Python function, traceback and failing input I paste below.
First explain the cause using the actual source.
Propose the smallest fix that preserves the public function signature and existing valid behavior.
Add a regression test for the supplied input plus one boundary case.

Format

State the Python version and any dependency assumptions.

Guardrails

If the traceback or source is missing, ask for it; do not invent a stack trace or rewrite unrelated code.
Example

Build a small file-report tool

Role

Python developer.

Context

Use the stated Python version, actual inputs and permitted dependencies.

Task

Write a Python 3.12 script that lists file extensions and total sizes under a folder I supply.
Use pathlib and the standard library, skip symbolic links and report unreadable files without crashing the entire scan.

Format

Return JSON with extension, count and bytes, sorted by extension.
Include installation-free run instructions and tests using a temporary directory with nested files and a symbolic link.

Guardrails

This is read-only: never rename, delete or upload files.

What makes a good Python code prompt

  1. State the Python version, operating system and permitted dependencies so the proposed code matches your environment.

  2. Provide a small real input and the exact expected result. Examples expose assumptions about types, units and formatting.

  3. Define file and network boundaries. Request read-only behavior when a task does not need to modify anything.

  4. Ask for errors and edge cases as part of the deliverable, not as an afterthought once a script fails.

  5. Require runnable tests and usage instructions. Run the code in a safe environment and inspect its behavior before trusting it.

Bad prompt vs What2Prompt prompt

Bad prompt

“write Python to process my data”

What2Prompt prompt

Role

Python developer.

Context

Use the stated Python version, actual inputs and permitted dependencies.

Task

Write a Python 3.12 standard-library script that reads a CSV with category and amount columns, validates Decimal amounts and writes category totals to a new file.

Format

Provide runnable code, usage instructions and tests with expected results.

Guardrails

Include sample input, expected output and tests; never overwrite the source.

The vague request hides the data format, environment and definition of success. The stronger brief specifies an observable result and safe file handling. Our prompt engine writes the brief; your coding AI still needs the real inputs and you still need to run its tests.

Begin with a task you can verify manually on a few rows or files. Keep source data intact, compare the result with your expected output and only then scale up. When debugging, send the smallest reproducing example rather than an entire private dataset. Python’s documentation is the reference for language and standard-library behavior; check third-party documentation separately when dependencies are needed.

Reference: Python documentation ↗

Questions about Python prompt generator

Which AI should I use for Python code?

Claude Code, ChatGPT and other coding assistants can help draft and explain Python. Choose one that can inspect the relevant files or accept your minimal example. Name the environment and dependencies, and evaluate the answer with tests rather than assuming one model always produces working code.

Why does AI-generated Python fail on my computer?

Common causes include a different Python version, missing packages, wrong file paths or unexpected input. Share the exact traceback, relevant code and a minimal sample without secrets. Ask for a diagnosis and a small fix, then rerun the failing case.

How can I check a Python script before running it?

Read its file operations, network calls and dependencies first. Use a virtual environment and disposable sample files. Ask for tests with concrete expected results, and avoid running unfamiliar code with elevated permissions. A detailed prompt guides the model but does not sandbox its output.

What2Prompt prompt engine, with the W2P mark on cobalt.

Give your next idea a better brief.