An AI-Tutor for students learning Python

[Cover art by Cyberpunk Portrait Generator API]

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 Python 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.


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

AI-Tutor + Colab

To let students easily interact with AI-Tutor, I integrated the service into Colab. Colaboratory, or Colab for short, is a creation from Google Research. Colab allows anybody to write and execute arbitrary Python code through the browser. I.e., you don’t need to have Python or an IDE installed on your computer.
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.


A task is a programming exercise that students need to solve. E.g.

  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


A solution is not provided to students, but a line of actions (strategy) is included. This is necessary since the AI-Tutor is not able to provide a consistent or correct approach for every task.


A strategy is a line of actions that students can follow to solve the task.
E.g., for the prime numbers task, 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?”
The 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.

Pseudo Code

Depending on the task, it might be helpful to include pseudo-code. E.g. for the prime numbers task, 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 coding editor that allows the student to write code and execute it.

Asking for feedback

Student can have the AI Tutor the evaluate their solution.

Take the 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 with Python installed will become alive to host this Colab notebook. FYI, 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 the 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.

The AI-Tutor is an open-source project:


Leave a Reply