Skip to content
Back to guides

Can AI write code?

Ask AI for a small code or formula example, ask it to explain the result and test it before use.

Estimated time
About 10 min

AI can suggest code, but you are responsible for using it

You are staring at a spreadsheet that needs a formula, or reading a short piece of code you cannot make sense of. AI can suggest a solution and explain it in a few minutes. For your first try, choose a small task and information you can check yourself.

Your goal for this session

Get a small suggestion from AI, ask for an explanation and test the result with sample data before using it for any real work.

Try your first coding exercise

  1. 1

    Choose a small, reversible task

    Start with a calculation formula or formatting an invented list of text: a task you can undo that does not require a real system or account.

  2. 2

    Use sample data

    Make up a few example rows yourself or use a version of a file with invented data, so that no real customer or employee information enters the conversation.

  3. 3

    Ask for an explanation and limits

    Ask what each part does, what it can change and what assumptions it relies on before deciding whether to run the suggestion.

  4. 4

    Test it and check the result

    Try the formula in a copy of the spreadsheet or a practice environment, and compare the result with an expected answer you calculated by hand or know in some other way.

Copy and try: a spreadsheet formula

Write a spreadsheet formula for an imaginary spreadsheet where cells A2:A6 contain integers. Calculate their average in cell A7. Explain each part, say what happens to empty cells and give a small test spreadsheet with expected results.

Ask for clarification in the same conversation

One of the cells A2:A6 is empty. Explain whether it counts as zero in the average in A7 or is left out of the calculation, and update the test spreadsheet to show this case.

Copy and try: check before running

Assess this code suggestion before I run it: "function total(items) { return items.reduce((sum, item) => sum + item, 0); }" Explain in plain language what it does, what it assumes about the input and how I would test it with a few example values before trusting it.

Improve the request so the result can be tested

From vague automation to a focused exercise

A common request:

Write a program that organises all my files.

Write a practice example that prints an invented list of five files in alphabetical order without touching real files. Explain the code line by line and give the expected result.

When do you need an expert?

  • The code handles personal data, money, passwords, a production system or customer information.
  • The code can send messages, make purchases, delete data or change permissions.
  • You cannot explain what the code does or how to undo the effects of an error.
  • The code will be used in a service that will be published or in a workplace system.

Once you know the basics

The next step is to learn to write test cases in advance and ask AI to assess its own solution critically.

Ask for and test a small code suggestion

The material stays visible throughout the exercise. Write your own request or assessment first. The hint and assessment criteria appear only after you have tried or selected “I don’t know yet”.

Use only the information in the material and imaginary code in your requests, rather than your own real files or systems.

Question 1/3

Question 1/3

The material describes how a vaccine works in four named stages: vaccination, antibody production, memory cell formation and rapid response. Write a request to AI asking for a short program or formula that prints these four stages in the same order as in the material. In the same request, also ask for sample output so that you can check that the program works correctly before using it.

Use the practice activity in your own AI service (optional)

Try code you can explain and test.

AI writes code quickly. You are responsible for what it does. Practise asking for a suggestion you can test before using it.

Experiment · about 10 min

Where shall we start?

How the request is built

Task
A converter and three values to check it
Background
Degrees Celsius to Fahrenheit
Format
Below freezing, room temperature, boiling point

Write me a small program that converts degrees Celsius to Fahrenheit. Then give three example values I can use to check the result myself: a temperature below freezing, room temperature and the boiling point of water. For each, tell me what the result should be.

Ready to try the experiment?

This exercise works with any assistant.

Open ChatGPT (opens in a new tab)

Understand and test before running: Test the suggestion with sample data first. Ask an expert to review it before running it with a real service, customer data, payment details or personal data.

Skills and concepts in this guide

Publication details and sources

Published:
July 23, 2026
Sources checked:
September 4, 2026

Related guides