ChatGPT learning programming. Non-obvious examples

ChatGPT learning programming. Non-obvious examples

AI usage scenarios for surface learning. The same ChatGPT as the default standard is used by students (and teachers too) to write texts (abstracts, coursework, diplomas, etc.), to analyze data, learn languages ​​and, of course, to solve problems. Let’s talk here about how you can use ChatGPT to teach programming. Typically, students and schoolchildren “feed” the condition of their task to the chat, and at the exit they receive the program code in the required language. Often, the chat also gives an explanation of the main points of the code, tells about the algorithm. This is how you can learn programming, having a “smart” consultant by your side. Not always, however, the chat code is adequate, and the solutions are complete. But these are obvious things. Let’s try to compile a list of examples here that can be useful to both those who study programming and those who teach. Let’s start with a simple one.

Analysis of program code

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

  • tell what task the code solves;

  • explain the code in lines;

  • 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 the listed tasks, but the quality of implementation and correctness are not guaranteed. It happens that he gets fixated on your task and issues the same thing. In this case, you should not torture the current dialogue, but rewrite the prompt (clarifying the task and making it more specific) and start a new chat.

Translation of program code from one language to another

With typical educational tasks, which were solved once and by someone, the chat copes 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 task condition to the code. Perhaps it is worth breaking the task into several simple ones. Here is an example of C++ code for translation (to show the level of complexity of the tasks), which the chat handles easily:

C++ starter code

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='')

Making tests for Moodle

Much to the delight of teachers who need to take tests in Moodle markup for distance learning or testing, ChatGPT can help. It knows the GIFT or Aiken markup, 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 creating a question in the chat is below:

Matching test question

See more examples here – here are our experiments with different question types for Moodle tests.

Compilation of block diagrams to the code

Perhaps this is the most interesting. You definitely remember your agony when you had to draw a block diagram of an algorithm or program code when you started teaching programming. All teachers sin by this, demanding to “pump” logic. As experience shows, half of the students do not need this, they can abstract without pictures and immediately write the logic of the algorithm in code. But the block diagram still needs to be drawn. And in those cases when flowcharts are really needed by someone who has a hard time writing code, and when this task is simply “must-have”, ChatGPT can help. However, there is another case when a block diagram is definitely necessary for a student – when writing a term paper or thesis, you always need content to fill out an explanatory note. And here block diagrams are an ideal option. The work has a solid appearance, there are a lot of pictures, and you need to write less text.

How does it work?

Obviously, the student, pupil or teacher has the free version of ChatGPT-3.5. And he does not draw pictures and, even more so, diagrams. However, there is a trick: you can ask the chat to write code for PlantUML markup for your programming task – either task-specific or out-of-the-box. And, miraculously, the chat is able to do this. Then it remains to send this code to the appropriate online service and receive a ready-made block diagram. Let’s give an example of PlantUML code and a block diagram for it for understanding:

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

And now the block diagram:

For reference, UML diagram syntax and flowchart examples can be found here.

Related posts