AI-Tutor helping students to learn Python

[Cover art by Cyberpunk Portrait Generator API]

You don’t need to be a pessimist to imagine a world where students let AI tools do their homework and teachers use AI tools to evaluate students’ submissions. Maybe there is still a chance for a better outcome.

For educators, it’s easy to perceive AI tools as a threat or a tool that almost invites students to cheat. Not as easy, but still plausible, is an approach that integrates AI tools into teaching.

For a given task like “write a program that prints the first 100 prime numbers,” it’s easy for students to open ChatGPT, enter the task, and copy/paste/submit the output. Not as easy, but certainly more rewarding, is an approach that allows students to embrace feedback from an AI-tool, before submitting their work.

AI-Tutor

I created a rather simple web service (dubbed AI-Tutor) that supplements incoming requests, before sending them on to a generative AI service.
To keep the conversation focused and to allow for follow-up questions, AI-Tutor maintains objective and context. It allows students to ask questions about a programming task and maybe more importantly, can evaluate a proposed solution and provide ongoing feedback.

AI-Tutor + Colab

To let students easily interact with AI-Tutor, I integrated the service into Colab. Google Research provides Colaboratory, or Colab for short, for free. Colab allows anybody to write and execute source code through their web browser. I.e., you don’t need to have Python or an IDE installed on your computer.
For instance, in Colab, users can write Python programs in Jupyter Notebooks. The code is placed into Jupyter cells and executed by pushing the execute button. Notebooks can easily be shared, by simply sharing a URL.

Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations, and explanatory text. It provides an interactive computing environment where you can write and execute code, visualize data, and document your work.
The name “Jupyter” is derived from the combination of three programming languages: Julia, Python, and R. These languages were the initial languages supported by Jupyter Notebook, although now it supports many other programming languages.
A Jupyter Notebook consists of a series of cells, which can contain code, markdown text, or raw text. You can execute the code cells interactively and see the results immediately below the cell. This allows for a more exploratory and iterative workflow, where you can run code in small chunks and examine the output as you go.

Task

A task is a programming exercise that students need to solve. Here are three examples:

  1. Find the first 100 prime numbers
  2. Roll a dice until you have rolled six twice in a row
  3. Ask a user for their name and output the number of vowels you found in the name

Solution

Solutions are not provided to students, but a line of actions (strategy) is included. This is necessary because, without it, AI-Tutor might not always provide a consistent and correct approach for every task.

Strategy

A strategy is a line of actions that students can follow to solve the task.
For the above-mentioned 100 prime numbers task, for instance, the strategy could be:

  1. Initialize an empty list to store the prime numbers.
  2. Start with a number, let’s say 2, and check if it is prime.
  3. If the number is prime, add it to the list of primes.
  4. Increment the number and repeat steps 3 and 4 until you have found 100 prime numbers.

Asking questions

At this point, students may have questions about the strategy, e.g. “What does it mean that a number is prime?” or “How would I do step 3?”
AI-Tutor will answer questions in the context of the given task and strategy. However, code snippets longer than 10 lines are removed from the answer.

Student question: What does it mean that a number is prime?



Student question: How would I do step 3?



Pseudo Code

Depending on the task, it might be helpful to include a pseudo-code. For the above-mentioned 100 prime numbers task for instance the pseudo-code could be:

Initialize an empty list to store the prime numbers
Set num to 2, the first prime number
While the length of the list of prime numbers is less than 100:
    Set is_prime to True
    For each integer i from 2 to the square root of num (inclusive):
        If num is divisible by i:
            Set is_prime to False
            Break out of the loop
    If is_prime is True:
        Add num to the list of prime numbers
    Increment num by 1

Coding Editor

The Colab notebook contains a rudimentary coding editor that allows students to write and execute code.

Asking for feedback

Students can ask AI-Tutor to evaluate their solution.



Taking AI-Tutor for a spin

Here are three Colab notebooks for you to try out:
  1. Print the first 100 primes
  2. Roll a dice until you roll a six twice in a row
  3. Count the number of vowels in a name

Colab Notebook Quick Start

The links above will open Colab Notebooks.

Step 1: click Connect, which means that somewhere a real computer will come alive to host this Colab notebook. Interestingly, during my testing, this computer was often located in the Netherlands.
Step 2: click the play button to initialize the tutor.

Step 3: click the next play button. A text input box will appear, allowing you to enter a question, which AI-Tutor will try to answer. If you have follow-up questions, just click the play button again.

Step 4: once you have come up with a solution, or just something intermediate, click the final play button, to receive feedback. Consider the response, improve your code, and iterate. You can do this step until you like the response you are getting.

Step 5: save your work. Click the Save copy in Drive option in the File menu.

If things go wrong, the Runtime menu is your friend. The nuclear option would be “Disconnect and delete runtime” and then simply reload the page.

Let’s see a demo …


Adding more Tasks

You can take a look at how AI-Tutor was implemented: https://github.com/wolfpaulus/ai_tutor

Taking a closer look at the three examples (*.ipynb files) should give you an idea of the work that’s involved, creating more AI-Tutor-based assignments.
At this point, I think it should take no more than about 15 minutes, from idea to colab notebook.

 

Leave a Reply