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.

How to use ChatGPT to write code

PC Guide is reader-supported. When you buy through links on our site, we may earn an affiliate commission. Prices subject to change. Read More

Last Updated on

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

7-in-1 AI Content Checker – One-click, Seven Checks

7 Market leading AI Content Checkers in ONE click. The only 7-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.
Only $0.00015 per word!

Winston AI detector

Winston AI: The most trusted AI detector. Winston AI is the industry leading AI content detection tool to help check AI content generated with ChatGPT, GPT-4, Bard, Bing Chat, Claude, and many more LLMs.
Only $0.01 per 100 words

Originality AI detector

Originality.AI Is The Most Accurate AI Detection.Across a testing data set of 1200 data samples it achieved an accuracy of 96% while its closest competitor achieved only 35%. Useful Chrome extension. Detects across emails, Google Docs, and websites.
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.

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 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.