// how to
How to Use ChatGPT to Write Code (Even as a Beginner)
Describe what you want the program to do in plain English, including the language and where it will run, and ask for one small piece at a time with an explanation. Run each piece, paste any error message back into ChatGPT, and never run code you don’t understand on important data.
The short version
ChatGPT is a patient programming tutor that writes code on request. The trick is to go in small steps: ask for one piece, run it, understand it, then ask for the next. Big all-at-once requests give you big, broken programs.
Step by step
- Describe the goal in plain English: “A script that renames all photos in a folder to their date.”
- Name the language and where it runs: Python on a Mac, JavaScript on a web page, Excel macros.
- Ask for the first small step, with an explanation of each line.
- Run it. If there’s an error, paste the full error message back.
- Ask for the next step only when the first one works.
- Ask it to explain anything you don’t understand before you build on it.
Prompts to copy
Start a small project:
I'm a beginner. I want [what the program should do]. I'm on [Windows / Mac] and can use [Python].
Break it into small steps. Give me only step 1: the code, how to run it, and what each line does.
Fix an error:
I ran your code and got this error:
[paste the full error message]
What does it mean, and what's the fix? Explain in simple terms.
Review it:
Review this code for bugs, security problems and anything a beginner might misunderstand:
[paste code]
Example
“Rename all JPG photos in a folder to the date they were taken” becomes: step 1, list the photos; step 2, read each photo’s date; step 3, rename a copy, not the originals; step 4, run it on the whole folder. Each step is short enough to understand and test.
Mistakes to avoid
- Asking for everything at once. You’ll get code you can’t debug.
- Running code on your only copy. Test on copies of files.
- Pasting secrets. Never paste passwords or API keys into a chat; use placeholders.
- Trusting package names blindly. AI sometimes suggests packages that don’t exist. Look them up before installing.
Going further
For serious projects, AI coding assistants that work inside your editor are more capable than a chat window. Start with our guides: set up an AI coding assistant and review AI-written code.
Related: write Excel formulas.
Frequently asked questions
Can I build an app with ChatGPT if I can't code?
You can build small tools and scripts, and learn a lot along the way. For a real app with users, payments and private data, you'll need someone who can review the code for security and maintain it.
Is code from ChatGPT safe to use?
Not automatically. It can contain bugs, security holes or references to software packages that don't exist. Test it, and have anything that handles money or personal data reviewed.
Free download
Get the AI Coding Starter Kit
A PDF you can use with any AI coding assistant: a project-rules template, 25 tested prompt patterns, a team adoption checklist and an assistant comparison sheet. The editable Markdown sources are included.
- Works with Copilot, Claude Code, Codex, Cursor and more
- Double opt-in, one-click unsubscribe
- No trackers, never shared