close
Cart icon
User menu icon
User icon
Lightbulb icon
How it works?
FAQ icon
FAQ
Contact icon
Contact
Terms of service icon
Terms of service
Privacy policy icon
Privacy Policy
Zdjęcie główne artykułu.

How can ChatGPT help with learning to code?

Most of you have probably heard of ChatGPT. And even if you haven't, you'll soon hear about it anyway. This language model is often described by many as a revolution on par with the invention of the printing press. At Codenga, we are deeply interested in learning to code. Let's see what possibilities ChatGPT offers in this regard.

In this article, we will be using an older, available for free version - ChatGPT 3. It should be noted that language generation algorithms are constantly evolving. What we show here may soon be outdated.

What does ChatGPT have to say about learning to code?

Let's ask a direct question to ChatGPT: "How can ChatGPT help with learning to code?" Here is a snippet of the response:

"As a language model, I can help with learning to code by providing information, tips, suggestions, and advice on various programming languages, programming techniques, algorithms, and data structures. You can ask me programming-related questions, and I will try to provide the best possible answer. For example, if you need help understanding certain programming concepts or are looking for ideas to solve a specific problem, I can assist you."

Language models operate on a language. Their main purpose is to generate text. Therefore, their greatest potential lies in generating tips, hints, and explanations. You must be aware that ChatGPT does not run code. It is neither a compiler nor an interpreter. It also struggles with math. So let's focus on its strengths. Let's ask some questions that are typical for beginner programmers and analyze the answers.

Example - explain a concept

Here is the query (prompt) we sent to ChatGPT 3:
"What is a loop in Python?"

And here is the response:
"A loop in Python is a programming structure that allows for the repetition of a specified block of code a certain number of times or until certain conditions are met. This allows a programmer to perform repetitive tasks without having to write the same lines of code multiple times."

In explaining the basic concept of a loop, ChatGPT does quite well. In addition to the explanation, ChatGPT also generated examples of using for and while loops. They can be clearly seen in the image below:

Learb how to use ChatGPT as a helpful tool for programming

Summary and conclusions

The examples and explanations regarding loops in Python are correct. ChatGPT generated correct code and described it properly. The output examples returned by the loop are also correct. From a content perspective, everything is OK.

It can be argued that ChatGPT is capable of explaining basic concepts. At least it managed to handle and explain basic loops in Python.

Example - solve a simple problem

Now we will try to use ChatGPT to find a solution to a simple programming problem. Here is our query:

"I need a function in Python that calculates the factorial for a given number."

This is the code proposed by ChatGPT:


def factorial(n):
    if n < 0:
        raise ValueError("The number cannot be lower that zero.")
    result = 1
    for i in range(2, n+1):
        result *= i
    return result


The code looks correct. It correctly calculates the factorial for the given number.

Summary and conclusions

ChatGPT has great potential as a tool for solving programming problems. However, it is important to remember one important thing. The code for calculating the factorial is a very simple problem that has been solved countless times. This is a standard task for beginner programmers. Therefore, it is not a great challenge for the language model.

Problems you need to be aware of

ChatGPT handles simple tasks quite well. It can explain basic concepts and solve simple problems. However, the internet is full of examples that somewhat undermine trust in this tool.

Sometimes, the code generated by the language model contains serious errors. One major problem is the phenomenon known as hallucinations, which refers to the tendency to generate fictitious responses. This includes suggesting the use of nonexistent tools or importing nonexistent libraries. Generally, the more complex the problem we try to solve, the more caution we need when using code generated by the model.

However, at the basic level, ChatGPT does quite well. We can reasonably trust it when we need explanations of simple concepts such as loop operations or variable usage. It can also be helpful when we want to write a simple algorithm, such as in our example of computing factorial. So, we can treat ChatGPT as a kind of virtual assistant that helps us learn programming. But we should also have some limited trust in it.

Also, don't forget that language models are evolving very quickly. In this article, we used ChatGPT 3, and now there is already a version 4 (paid). Therefore, it is worth carefully monitoring this field because there is certainly enormous potential in it.