To learn to code with AI, set the tool up as a tutor that gives hints and asks questions, not as a machine that hands you finished code, because the finished code is exactly the part you needed to practice.
It’s easy to feel like you’re progressing. You describe a problem, the AI returns a working solution, you run it, and it passes. A week later you open a blank file and can’t write a loop. The code got written, but you didn’t learn to write it.
This guide shows how to turn a chatbot into a practice partner: a rule set that forces hints, a “hint ladder” you climb one rung at a time, a prompt that quizzes you before it reveals anything, and a worked example in Python. You’ll also see what research actually suggests about unrestricted AI help and why a guarded setup matters. The exercises and conversations here are made up.
Contents
What the Research Suggests
Learning research points the same way. The Dunlosky and colleagues’ 2013 review of ten study techniques says practice testing, such as quizzing yourself, earned a high-utility rating, while rereading received a low one. Asking an assistant for finished code and reading it is closer to rereading; writing the code yourself and testing it is closer to practice testing. The review covered general study techniques, not programming specifically, so treat it as a reason for the hint-first rules below rather than proof of a coding result.
Harvard’s CS50 course offers a U.S. example of the hint-giving approach. Its AI tutor, the CS50 Duck, launched in spring 2023 on the ChatGPT API and is meant to be a “less-helpful version of ChatGPT.” According to the Harvard Gazette: Taming the Duck, for starters, it is instructed not to give students outright answers, its responses are screened by the team’s own code before students see them, and a “heart system” caps how many questions a student can ask in a period. The Duck asks more questions than it answers. The same article is candid about limits: the Duck was told not to give blocks of code yet does so up to a quarter of the time, and the course’s lead instructor calls it a net positive based on his experience, not on a measured learning result. That is a reason to set your own rules, as the next section shows, instead of trusting a tool’s guardrails.
Three Ways to Use AI While Learning
- What it gives you: Answer machine – Finished code; Explainer – Explanations of finished code; Hint-giving tutor – Questions, hints, feedback.
- Who writes the code: Answer machine – The AI; Explainer – The AI; Hint-giving tutor – You.
- Feels fast: Answer machine – Very; Explainer – Fairly; Hint-giving tutor – Slower.
- Builds the skill you’re practicing: Answer machine – Rarely; Explainer – Partly; Hint-giving tutor – Yes.
- Best for: Answer machine – Work you already understand; Explainer – Reading unfamiliar code; Hint-giving tutor – Learning something new.
The first two have their place later. This guide is about the third.
Set the Rules Before You Ask
The tool will happily give you answers unless you tell it not to. Start each session with a rule-setting message:
I'm learning to code, and I want you to act as a tutor, not an answer machine.
Rules for this session:
1. Do not write complete solutions to my exercises, even if I ask. If I ask for the answer, give me a hint instead.
2. When I'm stuck, give me hints in this order, one at a time, and wait for me to try after each: (a) a question that points at the issue, (b) a concept or function name I should look up, (c) a tiny example of a similar but different problem, (d) the shape of the solution in plain English, with no code.
3. After I write code, tell me what works, what doesn't, and why, without rewriting it for me.
4. Before explaining a concept, ask me what I think it does.
5. I'm using [language]. My level: [complete beginner / know the basics].
If I say "show me the answer," ask me to first explain my best attempt in words.
This prompt is my suggestion, not an official template.
The last line is the safety valve. It doesn’t forbid you from ever seeing the answer. It makes you do some thinking first.
The Hint Ladder
The ladder in rule 2 is the core of the method. Climb one rung at a time.
- 1. A question. What you get: A nudge toward the issue. Example for “find the largest number in a list”: “If you looked at one number at a time, what would you need to remember as you go?”
- 2. A pointer. What you get: A concept to look up. Example for “find the largest number in a list”: “Look up how a
forloop iterates over a list.” - 3. A similar example. What you get: A different but related problem. Example for “find the largest number in a list”: “Here’s how you’d find the total of a list. How is ‘largest’ different from ‘total’?”
- 4. The shape. What you get: Plain-English outline, no code. Example for “find the largest number in a list”: “Keep a ‘best so far’ value, compare each item, update it when you find a bigger one.”
- 5. Reveal. What you get: Only after rungs 1 to 4 and your own attempt. Example for “find the largest number in a list”: The full solution, to compare with yours.
Most of the learning happens before rung five. If you reach it, treat the solution as something to study and then rewrite from memory the next day.
A Worked Example in Python
Say the exercise (made up for this guide) is: “Write a function largest(numbers) that returns the biggest number in a list.”
You try first and write:
def largest(numbers):
for n in numbers:
if n > numbers[0]:
return n
You run it with [3, 9, 4], and it returns 9. It seems to work. Then you try [9, 3, 4] and it returns None. You’re confused and ask for help. The tutor, following your rules, does not rewrite the function. It says:
- “What happens in your function if no number is bigger than the first one?” (rung 1)
- You reply that it never returns anything.
- “What does a function return if it reaches the end without a
returnstatement?” (a pointer) - You realize it returns
None, and that you’re comparing everything only to the first item.
Then the tutor asks you to describe, in words, how you’d find the biggest number if you were checking cards one at a time. You say you’d remember the highest card so far. That’s rung 4, reached by you. You write:
def largest(numbers):
best = numbers[0]
for n in numbers:
if n > best:
best = n
return best
It passes. Notice that the AI never wrote a line of the solution, and you found your own bug. That’s what the setup is for. The exercise and conversation are invented, but the pattern fits any beginner problem.
Make It Quiz You
A tutor that only answers questions leaves you passive. Add a quiz step:
I just learned about [concept, e.g., for loops].
Please quiz me with three questions of increasing difficulty. Ask one at a time. Wait for my answer before you tell me whether I'm right. If I'm wrong, give me a hint, not the answer.
Include one question where I predict what a short piece of code will print, and one where I have to write a tiny function.
Predicting output is a useful skill because it forces you to simulate the code in your head, which is what reading code requires.
Using Code, Logging Struggles, and Checking What Stuck
When Is It Okay to Get Code?
Not never. There are good reasons to ask for finished code:
- Boilerplate you already understand. If you’ve written it ten times, let the tool save you the typing.
- Seeing a second solution after you’ve finished your own.
- Unfamiliar libraries, once you can read the result and explain each line.
- A stuck project where one blocker is stopping all progress, as long as you then study the fix.
A decent rule: if you couldn’t explain every line out loud, you aren’t ready to rely on it. In that case, go back to the ladder.
Keep a Struggle Log
After each session, write down:
- What you tried first
- What went wrong
- Which hint helped
- What you’d do differently next time
A few lines are enough. The log shows you patterns, like always forgetting to initialize a variable, and gives you something to review. It also keeps you honest about how far you got without help.
Check What Stuck, Without the Tool
Practice with AI feels productive. To find out what you actually learned, test yourself with the AI off. Our guide to coding practice without AI shows how to run a short weekly check. It’s the other half of this method: the tutor helps you learn, and the check tells you whether it worked.
If you want to learn to code with AI and still end up able to code without it, the rules in this guide are the difference.
Mistakes That Undo the Method
- Asking for “the answer” when you’re mildly annoyed. That’s usually when you’re closest to learning.
- Copying code you can’t explain. If you can’t say what a line does, you haven’t learned it.
- Skipping the first attempt. Even a wrong attempt gives the tutor something to work with.
- Letting the tutor drift. If it starts writing full solutions, restate your rules.
- Trusting every explanation. AI can be wrong. Check unfamiliar claims in the official documentation of your language.
Questions About Learn to Code With AI
How do I learn to code with AI without becoming dependent on it? Make it a tutor with rules: hints before answers, your attempt first, and regular practice with the AI turned off.
Is it bad to use AI to write code when I’m learning? It can undermine the practice you need. The Dunlosky review above rates self-testing high and rereading low, and reading a finished solution is closer to rereading. Use finished code after you’ve done the thinking, not instead of it.
Is it realistic to learn to code with AI as a complete beginner? Yes, if the tool works as a tutor with rules. In my view, beginners benefit from hints and questions while they build basic habits.
Can AI be a good coding tutor? It can, if you set it up to give hints and ask questions. Check its explanations, because it can make mistakes.
What should I do if the AI keeps giving me full solutions? Remind it of your rules at the start of the next message, or begin a new session with the rule-setting prompt.
Does this work for any programming language? The method does. Replace the language name in the prompt, and adjust the level.
Should I ask AI to explain error messages? Try reading the message yourself first. Then ask the tutor what the message means, not for the fixed code.
How often should I practice? Choose a schedule you can keep.
Start With One Exercise Today
Paste the rule-setting prompt into your AI tool, pick one small exercise, and write your first attempt before asking for anything. When you learn to code with AI this way, you spend more time stuck at first and much less time wondering why you can’t write code on your own.
This article offers general learning tips, not guarantees of results or job outcomes. The research cited has limits noted above. Exercises and conversations are fictional examples.
Sources:

Leave a Reply