Generate a function from a numbered comment spec

code & data

// what it does

Write the requirements as numbered comments and end with a leading word — the language keyword that starts the code, like import or def — to nudge ChatGPT straight into that language and pattern. OpenAI's best-practices guide uses exactly this trick to steer a Python function without a paragraph of prose.

// prompt

> # Write a Python function that: # 1. asks the user for a distance in miles # 2. converts miles to kilometers # 3. prints the result rounded to 2 decimals import

// gotcha

Generated code can call libraries that do not exist or APIs that changed. Ask for a runnable example with its imports, then actually run it — never paste generated code into production untested.

// resources