Home > Apps > Apps How To

How to use ChatGPT to write code

Can AI help you write code faster and more accurately? Let's look at how to use ChatGPT to write code.
Last Updated on January 30, 2024
How to use ChatGPT to write code
You can trust PC Guide: Our team of experts use a combination of independent consumer research, in-depth testing where appropriate - which will be flagged as such, and market analysis when recommending products, software and services. Find out how we test here.

One of the most seismic side-effects of LLMs trained on code, is the ability of software to write software. A recursive process, which only becomes more parabolic when we consider the emergent capability of AI that writes AI. Artificial intelligence can decide, not only how to program something, but what it should program next – an outrageously valuable tool for those who know how to wield it. Let’s look at how to use ChatGPT to write code.

Essential AI Tools

Editor’s pick
Only $0.00019 per word!

Content Guardian – AI Content Checker – One-click, Eight Checks

8 Market leading AI Content Checkers in ONE click. The only 8-in-1 AI content detector platform in the world. We integrate with leading AI content detectors to give unparalleled confidence that your content appear to be written by a human.
EXCLUSIVE DEAL 10,000 free bonus credits

Jasper AI

On-brand AI content wherever you create. 100,000+ customers creating real content with Jasper. One AI tool, all the best models.


10x Your Content Output With AI. Key features – No duplicate content, full control, in built AI content checker. Free trial available.


Experience the full power of an AI content generator that delivers premium results in seconds. 8 million users enjoy writing blogs 10x faster, effortlessly creating higher converting social media posts or writing more engaging emails. Sign up for a free trial.


Create SEO-optimized and plagiarism-free content for your blogs, ads, emails, and website 10X faster. Start for free. No credit card required.

How to use ChatGPT to write code

Writing code with ChatGPT is surprisingly easy. Make sure to check “What is ChatGPT – and what is it used for?” as well as “17 ChatGPT Alternatives in 2023 – free and paid options” for further advice on this topic. AI Chatbots can take any programming language for which they have tokens (examples of) in their training data. Common programming languages include Java, Javascript, Python, C++, PHP, HTML, CSS, Ruby, and SQL.

The goal here is to take an input – a piece of code – and by following simple instructions about what modifications the software developer would like, output useful code with fixes applied. The generated code should not add any new bugs or produce a new error message. The complex code may be simplified and redundancies may be removed.



Create an OpenAI Account

Go to https://chat.openai.com/auth/login in any web browser and sign up for an OpenAI account.

Sign up ChatGPT



Prime your prompt

Begin (or end) your prompt by letting ChatGPT know you want code as your output. For example, you can say “Acting as a senior software engineer, write the code for a calculator app using Python. Output only code and nothing else.”




Artificial intelligence is, at last, very good at writing bug-free code. In fact, it is inherently good at removing human error. However, an LLM is only as good as its training data, and the algorithms that formed its parameters. It also will be subject to the same biases as the humans who selected the training data. You should still proof-read your generated code, or at the very least have it checked by a totally separate AI.

Does ChatGPT help with coding?

Yes, Chat GPT can improve the speed of your programming by several times without sacrificing the accuracy or neatness of your code. This is particularly true for repetitive tasks that can’t be handled with a simple copy & paste.

How can ChatGPT help me learn Python code?

Python is an extremely pertinent choice to learn for your programming career, as many AI software’s are built with it. You can practice programming within the text box on OpenAI’s ChatGPT website from within your browser. The conversational nature of an AI chat bot allows it to respond to your practice attempts with helpful feedback and corrections in natural human language, the same way a human teacher would.

How good is ChatGPT at refactoring code?

Refactoring code is the process of re-writing existing code without altering its external behaviour i.e. the user experience. There are multiple ways to achieve the same result with any programming language, and refactoring is often done to simplify the code itself which makes it easier and cheaper to maintain. Developers thus far generally agree that ChatGPT is good at refactoring code.

Steve is an AI Content Writer for PC Guide, writing about all things artificial intelligence. He currently leads the AI reviews on the website.