Learning to code used to mean staring at a textbook, getting stuck on a single error message for hours, and wondering whether programming was simply not for you. In 2026, that has changed completely. ChatGPT and Claude act as patient, always-available tutors that explain code in plain English, fix your mistakes, and build practice projects with you, one step at a time. The catch is that the quality of what you get back depends entirely on the quality of what you ask. A vague prompt gets a vague answer; a well-built prompt gets a personal lesson.
This guide gives you 20 copy-paste AI prompts for learning to code, grouped by exactly what you need at each stage: starting from zero, understanding code you did not write, debugging errors, building real projects, and testing yourself. Every prompt works in both ChatGPT and Claude, and every one is written for a complete beginner. You do not need a paid plan, and you do not need any previous experience. You only need to copy the prompt, fill in the square brackets, and run the code you get back.
Why AI Is the Best Coding Tutor Beginners Have Ever Had
A traditional tutorial cannot answer your follow-up question. An AI tutor can, instantly, at 2am, in whatever words make sense to you. Ask it to explain a loop as if you were twelve years old and it will. Ask it to explain the same loop as if you were a maths teacher and it will do that too. That flexibility is the whole advantage: you control the pace, the level, and the examples.
AI coding assistants are also unusually good at the two things that stop most beginners. First, they explain code line by line instead of expecting you to read a whole file and understand it at once. Second, they debug with you: paste the exact error message and they will tell you what it means in plain words, then show you the corrected code. Both ChatGPT and Claude are strong at this, and both offer free plans that are more than enough for learning. Claude is widely praised for clean, well-explained code, and Anthropic also offers Claude Code, a tool that can build and edit whole projects from plain-English requests. ChatGPT, meanwhile, can run supported Python code directly inside the chat, which is handy for quick experiments and data tasks. For a beginner, the difference between the two matters far less than how you ask, so pick whichever you already use and focus on the prompts below.
There is one habit to build from day one: always run the code yourself. An AI answer is a starting point, not a finished product. Type it into a free editor such as Visual Studio Code, run it, break it, and paste the error back. That loop — ask, run, break, fix — is where the learning actually happens.
How to Write a Coding Prompt That Actually Works
Before the 20 prompts, learn the structure behind them, because it turns every future prompt you write into a good one. OpenAI's Codex best-practices guide structures a coding request in a few clear parts, and they work just as well in an ordinary ChatGPT or Claude chat. Every prompt in this guide follows the same pattern:
1. Give it a role. Start with who the AI should be: "You are a patient coding teacher" or "You are a senior Python developer". A role sets the tone and the level of the answer.
2. State the goal in one sentence. Say exactly what you want the code to do, in plain words. "Write a function that reads a CSV file and returns total sales per month" beats "help me with a CSV" every time.
3. Add context. Name the language and the version, paste the relevant code or the full error message, and say what you have already tried. An AI cannot debug code it cannot see.
4. Set constraints. Tell it what to use and what to avoid: "Use only the Python standard library", "Keep it under 30 lines", "Add a comment on every step". Constraints stop the AI from reaching for libraries you have never heard of.
5. Say how you will check it. Ask for a small example you can run, a test case, or the exact steps to see the result in your browser. If you cannot check the answer, you cannot trust it.
Keep those five parts in mind and you will rarely get a useless answer again. Now for the prompts themselves: copy any of them, replace the square brackets with your own details, and paste them into ChatGPT or Claude.
20 AI Prompts for Learning to Code in 2026
Start From Zero: Prompts 1–3
Prompt 1: Choose your first language
I'm a complete beginner and I want to learn to code. I want to [build websites / automate boring tasks at work / analyse data / build simple apps]. I can practise for [30 minutes] a day. Recommend ONE programming language for me, explain in plain English why it fits my goal, and give me a realistic 4-week learning plan with one small project per week.
Prompt 2: Build a 30-day learning plan
You are a patient coding teacher. I am a complete beginner learning Python. Create a 30-day learning plan with one 30-minute lesson per day. Each day should have one concept, one tiny example I can type and run, and one mini exercise. Start from zero and finish with me building a small working project. Explain everything as if I'm 12 years old.
Prompt 3: Explain a concept with a real-life analogy
Explain what [a variable / a function / a loop / an API] is using a real-life analogy from everyday life, then show a very small code example in [Python / JavaScript] with a comment on every line. After the example, ask me one question to check I understood it.
Understand Code You Did Not Write: Prompts 4–6
Prompt 4: Explain code line by line
Explain this code line by line as if I am a complete beginner. For each line, say what it does in plain English and why it is there. At the end, summarise in two sentences what the whole program does. [Paste the code here]
Prompt 5: Translate code between languages
This code is written in [JavaScript]. I am learning [Python]. Rewrite it in Python, keeping the same behaviour, and after each Python line add a short comment explaining what changed and why. [Paste the code here]
Prompt 6: Summarise a whole file
I found this code online and I don't understand it. First give me a one-paragraph summary of what it does. Then list the three most important parts and explain each one simply. Finally, tell me which parts are safe for a beginner to change and which parts I should leave alone. [Paste the code here]
Debug Like a Pro: Prompts 7–9
Prompt 7: Decode an error message
This [Python / JavaScript] code should [what it should do], but it crashes with this exact error: [paste the full error message]. Find the likely cause, explain it in simple words a beginner can understand, show me the corrected code, and tell me how to avoid this mistake next time. [Paste the code here]
Prompt 8: Find the bug without the error
This code runs without an error, but the result is wrong. It should [expected result], but it actually gives [actual result]. Walk me through the code step by step, find the bug, explain why it causes this result, and show the fixed version with a comment marking the change. [Paste the code here]
Prompt 9: Rubber-duck debugging
Act as my rubber duck. I will explain my code to you out loud, and after each part, ask me one question that makes me think about what that part actually does. Don't give me the answer yet — just ask questions until I spot the problem myself. Here is my code and what I think it should do: [paste code and description]
Build Real Projects: Prompts 10–13
Prompt 10: Your first webpage
I'm a complete beginner and I don't know how to code. I want a simple one-page website for [my dog-walking business / my portfolio / my local club] with my name, three services with prices, and a contact button. Write the complete HTML and CSS, then explain step by step, in plain English, how to see it in my browser. Explain anything technical as if I'm 12.
Prompt 11: A to-do app that teaches you the basics
You are a senior web developer who writes clean, well-structured code. Build me a simple to-do list app in HTML, CSS and JavaScript that lets me add a task, tick it off, and delete it. Use modern best practices and semantic HTML, include helpful comments explaining key parts, and after the code explain the three JavaScript ideas I need to understand to follow it.
Prompt 12: Automate a boring task
Write a Python 3.12 script that [renames all the files in a folder / reads a spreadsheet and summarises it / checks a folder for new files]. Use only the standard library. Add a comment on every step, keep it under 40 lines, and at the end explain how to run it on my computer and what to change if my folder is in a different place.
Prompt 13: Turn an idea into a project plan
I want to build [describe your app idea in one sentence] but I don't know where to start. Break it into five small steps a beginner can finish one at a time. For each step, tell me what I will learn, what code I will write, and how I will know the step is done. Don't write the full code yet — just the plan.
Practise and Test Yourself: Prompts 14–16
Prompt 14: Quiz me on what I just learned
Quiz me on [loops / functions / lists / variables] in Python. Ask me one question at a time. Start easy and get harder. After each answer, tell me if I was right, explain the correct answer in one sentence, and then ask the next question. Give me a score out of 10 at the end.
Prompt 15: Exercises that get harder
Give me five practice exercises in [Python / JavaScript] about [functions]. Start very easy and make each one a little harder. Give me only the first exercise now. When I send you my solution, check it, explain any mistakes, and only then give me the next one.
Prompt 16: Review my code like a senior developer
Review this code as if you were a senior developer reviewing a junior colleague's first pull request. Point out three things I did well and three things to improve, in order of importance. Explain each improvement in plain English and show a small example of the better version. Be encouraging but honest. [Paste the code here]
Go Further: Prompts 17–20
Prompt 17: Refactor my beginner code
Here is some code I wrote as a beginner. It works, but I know it is messy. Rewrite it more cleanly, keeping exactly the same behaviour. After the new version, list each change you made and explain in one sentence why it is better. [Paste the code here]
Prompt 18: Learn to write tests
Explain unit testing to a complete beginner in plain English, using a cooking analogy. Then take this function and write three simple tests for it: one normal case, one edge case, and one case that should fail gracefully. Show me how to run the tests. [Paste the function here]
Prompt 19: Learn Git without the fear
Explain Git and GitHub to a complete beginner as if I have never used them. Use a real-life analogy, then give me the five commands I need for 90% of daily work, with one sentence each on when to use them. Finish with a tiny practice exercise I can do in ten minutes.
Prompt 20: Prepare for a junior developer interview
I am learning to code and I want to apply for junior developer roles in [3 / 6] months. I know [Python / JavaScript] at a beginner level. Give me a realistic interview preparation plan: the five topics I must be able to explain, three common beginner interview questions with model answers, and one small project I can build to talk about in interviews.
ChatGPT or Claude for Learning to Code?
Both tools are excellent, and the gap between them is smaller than the gap between a vague prompt and a clear one. If you already pay for one of them, stay with it; switching will not teach you faster. If you are choosing from scratch, here is the honest breakdown.
Choose ChatGPT if you want one tool that does a bit of everything: chat, images, voice, file analysis, and a huge library of tutorials online. Its ability to run supported Python code directly in the chat is genuinely useful when you are learning, because you can test a snippet without leaving the conversation. Choose Claude if you want the cleanest, best-explained code and a calmer, more structured teaching style; it is the favourite of many working developers for exactly that reason. Claude's Projects feature also lets you keep your instructions and course notes in one workspace, so every new chat already knows your context. When your projects outgrow the chat window, both companies offer a next step: OpenAI has Codex, a coding agent that works directly in your repository, and Anthropic has Claude Code, which builds and edits whole projects from plain-English requests in your terminal.
The practical advice is simple: use the free plan of either tool for learning, and only consider a paid plan when you hit its usage limits regularly. Free plans are good enough for every prompt in this guide. And whichever you choose, try the same prompt in the other tool once in a while — comparing two explanations of the same idea is one of the fastest ways to understand it deeply. If you want to go further with AI-assisted development, our guide to how to use Cursor voice chat with agents shows how voice-controlled coding works, and our guide to building an AI agent stack explains how developers chain these tools together.
Free Tools to Practise With
You do not need to spend money to learn to code with AI. Start with Python, the friendliest first language for most beginners, which is free to download and runs on any computer. Write your code in Visual Studio Code, the free editor used by millions of developers, which highlights errors and works with AI assistants. Practise the fundamentals on freeCodeCamp, which offers free interactive lessons and projects, and save your work on GitHub, where a free account stores your code and shows future employers what you have built. When you want a second opinion on a prompt, paste it into the other chatbot and compare the answers. All of these tools are free, and together they cover everything in this guide.
Mistakes Beginners Make With AI Coding Prompts
The most common mistake is copying code without running it. AI can produce code that looks perfect and still fails, so never trust an answer you have not executed. The second mistake is asking for an entire app in one prompt. AI works best in small pieces: ask for one function, test it, then ask for the next one. The third mistake is pasting code you do not understand into a real project, especially code that handles passwords, payments, or personal data. If you cannot explain what a line does, do not ship it.
Two safety rules matter more than the rest. Never paste passwords, API keys, or private data into a chatbot, and never ask an AI to write code that accesses someone else's account or system. Keep your practice projects local, learn in the open, and check anything security-related against official documentation. AI is a tutor, not a substitute for understanding, and the developers who get the most from it are the ones who question its answers instead of accepting them blindly. For a lighter look at what AI prompts can do beyond code, see our 20 AI prompts for creating GIFs in ChatGPT.
Frequently Asked Questions
Can I learn to code using only ChatGPT or Claude?
Yes, for the fundamentals. AI tutors explain concepts, debug your errors, and set exercises at your level, which covers the first months of learning well. You will still need to practise on real projects and read other people's code, because the skill is in writing code yourself, not in reading AI answers. Treat the chatbot as a tutor, not as the whole course.
Which programming language should I learn first?
For most beginners, Python. Its syntax reads almost like English, it is used for websites, data analysis, automation, and AI itself, and there are more beginner tutorials for it than for any other language. If your goal is specifically to build websites, start with HTML, CSS, and JavaScript instead. Use Prompt 1 above and let the AI recommend based on your actual goal.
Do I need a paid ChatGPT or Claude plan to learn coding?
No. Both tools offer free plans that are enough for learning: chatting, asking for explanations, debugging, and writing small programs all work on the free tier. Paid plans mainly add higher usage limits and access to the most powerful models, which only matters once you are coding for hours a day. Start free and upgrade only if you keep hitting limits.
Is using AI to learn coding cheating?
No, as long as you are learning from it rather than copying blindly. Asking an AI to explain a concept is no different from asking a teacher, and professional developers use these tools every day. It becomes a problem only if you submit AI-written work as your own in a course or interview, or if you ship code you do not understand. Learn the ideas, run the code, and make the understanding yours.
#AIPrompts #LearnToCode #ChatGPT #Claude #CodingForBeginners #AICoding #Python #Programming #CodeWithAI #NextGenAIVibe
Comments (0)