ChatGPT for learning programming. Not obvious examples

Scenarios for using AI for surface learning. The same ChatGPT as the default standard is used by students (and teachers too) for writing texts (essays, coursework, diplomas, etc.), for data analysis, learning languages ​​and, of course, for solving problems. Let's talk here about how you can use ChatGPT to teach programming. Typically, students and schoolchildren “feed” the conditions of their problem to the chat, and as a result they receive the program code in the required language. Often the chat also gives explanations of the main points in the code and talks about the algorithm. This is how you can learn programming with a “smart” consultant at your side. However, the chat code is not always adequate and the solutions are complete. But these are obvious things. Let's try to compile a list of examples that may be useful to both those who study programming and those who teach. Let's start with something simple.

Program code analysis

You can offer the chat a fragment or ready-made code of a program or function and ask it:

  • tell what problem the code solves;

  • explain the code line by line;

  • add comments to the code;

  • find syntax errors in the code;

  • find logical errors in the code;

  • optimize the code (reduce memory consumption or speed up execution);

  • reduce the complexity of the algorithm;

  • change the paradigm, for example create classes (OOP);

ChatGPT is able to perform all of the listed tasks, but the quality of implementation and correctness is not guaranteed. It happens that he gets fixated on your task and produces the same thing. In this case, you should not torture the current dialogue, but rewrite the PM (clarifying the task and making it more specific) and start a new chat.

Translating program code from one language to another

With typical educational tasks that have already been solved once and someone can handle the chat without problems. New and complex tasks can also be translated from one language to another, but it is always worth testing the result. Sometimes you can add a text condition of the task to the code. It may be worth breaking the task down into several simple ones. Here is an example of C++ code for translation (to show the level of complexity of the tasks) that the chat can handle without difficulty:

C++ Starter Code

#include 
using namespace std;
int main()
{for (int i = 0; i < 5; i++) 
for (int j = 0; j < 15; j++) 
{cout << '+';}
cout << endl;}
return 0;}

Translated Python code

for i in range(5):
    for j in range(15):
        print('+', end='')
    print()

Writing tests for Moodle

To the great delight of teachers who need to write tests in Moodle markup for distance learning or testing, ChatGPT can be a great help. It knows the markup of GIFT or Aiken and after a little training on your topic, the chat successfully generates test questions with the correct markup. Here are examples of such test questions:

::1::Кто разработчик языка Pascal?{
    =Никлаус Вирт
    ~Блез Паскаль
    ~Билл Гейтс
    ~Питер Нортон
}

An example of generating a question in chat is below:

Compliance test question

Compliance test question

See more examples Here – here are our experiments with different types of questions for Moodle tests.

Drawing up flowcharts for code

Perhaps this is the most interesting thing. You definitely remember your agony when you had to draw a flowchart for an algorithm or program code when you started learning programming. All teachers are guilty of this, demanding to “pump up” logic. As experience shows, half of the students do not need this; they are able to abstract themselves without pictures and immediately write the logic of the algorithm in code. But, the block diagram still needs to be drawn. And in cases where flowcharts are really needed by someone who has difficulty writing code, and when this task is simply a “must-have,” ChatGPT can help. True, there is one more case when a flowchart is absolutely necessary for a student – when preparing a coursework or dissertation, you always need content to fill out the explanatory note. And here flowcharts are an ideal option. The work looks solid, there are a lot of pictures, but you need to write less text.

How it works?

Obviously, a student, student or teacher has a free version of ChatGPT-3.5. But he doesn’t draw pictures, much less diagrams. However, there is a trick: you can ask the chat to write code for PlantUML markup for your programming task – according to the task conditions or using ready-made code. And, lo and behold, the chat can do this. All that remains is to send this code to the appropriate online service and get a ready-made block diagram. For understanding, here is an example of PlantUML code and a block diagram for it:

start
:Конструктор блок-схем;
while (Создать блок-схему?) is (Да);
:Вводим код блок-схемы;
:Блок-схема генерируется;
:Сохраняем картинку;
:Делимся с друзьями;
:Пишем комментарии;
endwhile (Нет);
stop

And now the block diagram:

For reference, see UML diagram syntax and flowchart examples. Here.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *