Learn to code with AI without skipping the learning
ChatGPT or Claude matters less than how you set it up. Make it a tutor, write each piece yourself first, use it to explain errors and code, and test yourself without it every week.
- What this is
- How to use a chat assistant such as ChatGPT or Claude as a tutor while you learn to write computer programs yourself.
- Why it matters
- You build the skill to write and fix code on your own, instead of finishing tasks and only feeling as if you learned.
- The short version
- Either assistant works. Set it up as a tutor that gives hints before answers and asks you to predict what code will do.
- Write it yourself first, run it, read the error, then ask for a hint. Compare with a model answer only after yours runs.
- Once a week, write a small program with the assistant closed. Let it write code for you only once you can read and test it.
On this page
Short answer
Use whichever assistant you already have. We found no study comparing ChatGPT and Claude for learning to code, and the studies below suggest the setup matters more than the brand. Tell it to act as a tutor: hints before answers, explanations you then test by predicting output, and no full solutions. Write each piece yourself first, and once a week write something with the assistant closed. The routine below is our suggestion.
For general study rules (any subject), see Learning with AI without losing the learning. To build things with an agent (an AI that can take actions, such as writing and running code, not only chat) without learning to code, see Coding agents for people who don't write code. This page is for learning to write the code yourself.
What the studies show
Asking for answers can cost the learning. In a maths trial, a hints-not-answers tutor avoided the exam drop that unrestricted ChatGPT caused (Bastani et al., PNAS 2025; see Learning with AI without losing the learning). That was maths, not coding, but the pattern repeats below.
The same for coding, especially debugging. In an Anthropic trial, 52 mostly junior software engineers learned Trio, a Python library (a ready-made bundle of code). The AI group "averaged 50% on the quiz, compared to 67% in the hand-coding group", and "finished about two minutes faster, although the difference was not statistically significant". The largest gap was on debugging (finding and fixing errors) questions. Those who scored well tended to ask conceptual questions or ask for explanations along with code (Shen and Tamkin, Anthropic, 2026). The publisher sells an assistant, and the two high-scoring groups named here were small (7 and 3 people).
Used as a helper, it need not hurt. In a controlled experiment with 69 novices aged 10 to 17 on 45 Python tasks, access to a code generator (OpenAI Codex) made code-writing scores 1.8 times higher, "while not decreasing performance on manual code-modification tasks". A week later the Codex group did slightly better on post-tests, "although this difference did not reach statistical significance" (Kazemitabaar et al., CHI 2023).
Struggling students may not notice they are struggling. In 21 lab sessions with novice programmers, 20 of 21 finished the problem. Struggling students "thought they performed better than they did, and finished with an illusion of competence" (Prather et al., ICER 2024). Finishing a task is not evidence that you learned it.
Confident answers can be wrong. In one study of the free GPT-3.5 version, "52% of ChatGPT answers contain incorrect information" (Kabir et al., CHI 2024; more in Fix a computer, phone or app problem with AI, safely).
Set it up as a tutor
Paste this at the start of a chat, or save it as custom instructions or a project (settings that keep standing instructions for every chat):
I am learning <LANGUAGE> from scratch. Act as my tutor, not my coder.
- Never give me a full solution unless I type "SHOW SOLUTION".
- When I am stuck, give one hint at a time, smallest first.
- When you explain code, ask me to predict its output before I run it.
- When I share an error, help me read the message. Do not fix it for me.
- If you are not sure something is correct for <LANGUAGE_VERSION>,
say so and point me to the official documentation.
My current level: <LEVEL>. Today's goal: <GOAL>.
Replace the following:
<LANGUAGE>and<LANGUAGE_VERSION>: such asPythonandPython 3.<LEVEL>: such asI can write loops and if statements, not functions yet.<GOAL>: one small thing, such aswrite a function that counts words in a sentence.
Built-in study or learning modes do a similar job; Learning with AI without losing the learning lists them.
The practice loop
To run code you need the language on your computer. For Python, Python For Beginners shows how to install it.
| Step | What you do | Check |
|---|---|---|
| 1. Write it | Write the code yourself, even if it is wrong. | You typed every line. |
| 2. Predict | Say what it should print before you run it. | Your prediction is written down. |
| 3. Run it | Run it and compare with your prediction. | You know where they differ. |
| 4. Read the error | Read the last line of the error and the line number it names. | You can say what kind of error it is. |
| 5. Ask for a hint | Paste the code and the error, and ask for one hint. | You fixed it yourself. |
| 6. Compare | Once yours runs, ask for a model answer and the differences. | You can explain each difference. |
To understand an error or someone else's code, ask for an explanation, not a fix:
Explain this <ERROR_OR_CODE> line by line in plain words.
Do not rewrite it. After the explanation, ask me one question
that checks whether I understood it.
---
<PASTE_HERE>
Replace <ERROR_OR_CODE> with error message or code, and <PASTE_HERE> with the error or code itself. Keep API keys (secret codes that let programs use a paid service), passwords and personal data out of what you paste.
Build small projects. Exercises teach syntax (the spelling and grammar rules of code); small projects teach you to break a problem down. Examples (illustrative): a tip calculator, a program that renames files in a test folder, a word counter for a text file, a quiz that reads questions from a file. Ask the assistant to help you plan the steps, then write each step with the loop above.
Check it against the official docs. If you are new to programming, start from Python For Beginners, which links guides for people who have never programmed. The official Python Tutorial says it "is designed for programmers that are new to the Python language, not beginners who are new to programming", so it suits the stage after your first few weeks. When an answer names a function or option, look it up there before you rely on it (Check before you trust).
The weekly check
When to let it write code
How to tell it worked
- You can write a small program from a blank file without the assistant.
- You can read an error message and say what it means before you ask.
- You can explain every line of your projects to someone else.
- When the assistant is wrong, you notice.
Sources
- Bastani H et al. Generative AI without guardrails can harm learning: evidence from high school mathematics. PNAS, 2025. Randomised trial, nearly 1,000 students. Link
- Shen JH and Tamkin A. How AI assistance impacts the formation of coding skills. Anthropic, 2026. Randomised trial, 52 engineers; vendor. Link
- Kazemitabaar M et al. Studying the effect of AI code generators on supporting novice learners in introductory programming. CHI 2023. Controlled experiment, 69 learners aged 10 to 17. Link
- Prather J et al. The widening gap: the benefits and harms of generative AI for novice programmers. ICER 2024. Lab study, 21 students. Link
- Kabir S et al. Is Stack Overflow obsolete? An empirical study of the characteristics of ChatGPT answers to Stack Overflow questions. CHI 2024. Peer-reviewed study, 517 questions. Link
- Python Software Foundation. Python For Beginners and The Python Tutorial. Official documentation. Beginners · Tutorial
Changes
- v1.010 Oct 2026first version
- Time to do it
- 30 to 60 minutes per practice session, 20 minutes for the weekly check (our estimate)
- Sources
- 7
- Updated
- 10 Oct 2026
- Last checked
- 10 Oct 2026