Artificial intelligence in learning programming

Lesson 3 of 9 · Resources

AI assistants (ChatGPT, Claude, Gemini, Copilot…) can explain an error, suggest a solution and write code in a few seconds. How do you use them so that you learn more, not less? And what is allowed in competitions and in tests?

Before you start: required prior knowledge – trends in programming.
How to read: the page is an overview for students and teachers; at the end there is a short quiz, and the links lead to lessons on this site where the topic is taught in detail.
New course: if you want to find out what artificial intelligence is, how it came about and how a machine learns, see the course Artificial intelligence – start with the lesson What is artificial intelligence?

What an AI assistant does well, and what it does not

Does wellOften gets wrong
explains a compiler error messagetasks with precise limits (time, memory)
explains what a given piece of code does, line by lineedge cases: n = 0, an empty array, overflow
gives examples for a concept you do not understand"invents" functions or libraries that do not exist
suggests test casesclaims that wrong code is correct – confidently
helps tidy up code and add commentsunderstands what the teacher asked for in the task

According to the Stack Overflow 2026 survey, about 83% of programmers use AI tools, but only about half trust the result when they can easily check it, and only 6.6% would let it make important decisions. For a student it means the same: AI is a helper, but you are the one who checks.

How to learn with AI, not instead of yourself

  1. Try it yourself first. Work on the task for at least 15–20 minutes. Write down what you know, draw an example.
  2. Ask for a hint, not a solution. Write: "Don't give me code. Give me just one hint on how to start."
  3. Ask "why". "Why is it <= here and not <?" – questions like that teach you.
  4. Check it yourself. Run the program on the examples from the task and on your own examples (the smallest, the largest, edge cases).
  5. Explain it back. If you cannot explain the code the AI wrote in your own words, you have not learned it.

Examples of good questions:

  • "The compiler says expected ';' before '}'. What does that mean? Don't fix the whole program."
  • "Explain binary search to me on the array 2 5 8 12 16, step by step."
  • "Make me 5 practice tasks on loops, from easier to harder, without solutions."
  • "My solution works for small numbers, but for n = 100000 it is slow. What is the problem? Give me just an idea."

Rules: competitions, tests, homework

AI tools are not allowed in informatics competitions – not in the qualifications on Petlja, nor in the municipal, regional and national competitions, nor in the Serbian Informatics Olympiad (SIO). The solution must be yours. That is why the goal of practising is to be able to solve tasks without help.
  • Tests and exams: are done on your own.
  • Homework: ask your teacher what is allowed. If you use AI, say how you used it.
  • Projects (a creative programming project, a website, a game): AI can help, but you must understand and be able to explain every part of the code.

Privacy and safety

  • Do not enter personal data (your full name, address, phone number, passwords) into AI tools.
  • Many tools have terms of use with a minimum age – for younger students a parent opens and supervises the account.
  • An AI answer is not a source: when you write a paper, check the facts in a book, the documentation or on an official site and cite that source.

Exercise: find the mistake the AI made

For the task "print the sum of the digits of the number n (0 ≤ n ≤ 1018)" the AI gave this program. It works for most numbers – but not for all of them. Find when it does not work before you look at the explanation below.

#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    int sum = 0;
    while (n > 0) {          // for n = 0 the loop does not run – that is fine (the sum is 0)
        sum += n % 10;
        n /= 10;
    }
    cout << sum << endl;
    return 0;
}
Explanation

The program is correct for all numbers that fit in an int. But the task says "n up to 1018" – then int is not enough and you need long long n;. The AI "forgot" the limit from the task statement. Always check the data type and the limits!

Common mistakes and tips
  • Do not hand in code you do not understand as your own.
  • Check every answer by running the program on examples.
  • There is no AI in competitions – practise without it too.

Check your knowledge

Open the quiz

Artificial intelligence in learning

1. Is it allowed to use AI tools in informatics competitions?




2. Which question to an AI helps learning the most?




3. What do you do with code an AI has suggested?