Real Python has hundreds of coding exercises that let you practice what you’ve learned in a tutorial or course. Each exercise gives you a task, a code editor, and a set of tests that check your solution. When all the tests pass, you’ve solved the exercise.
Sometimes, though, the tests keep failing and you can’t figure out why. At that point, it’s tempting to open the solution and copy it. The tests turn green, but you don’t learn much from it.
Mentor AI is an AI tutor built into the Real Python platform. It can help you get unstuck on a coding exercise without handing you the answer. You open it by clicking the round orb in the bottom-right corner of any page or using the Ctrl+M shortcut. If the orb covers something you want to read, then you can drag it anywhere on the screen:
Mentor AI knows which tutorial, lesson, or exercise you’re looking at. On an exercise page, it can also look at the code you’ve run and your test results, so you don’t have to copy them into the chat. You can ask it to explain a failing test, give you a hint instead of the answer, or check whether you’ve understood an idea.
In this tutorial, you’ll learn how to:
- Run the tests and read the results before asking for help
- Ask Mentor AI why a test failed without pasting any code
- Check your understanding by predicting what the code does
- Ask for a hint about a specific failing test instead of the full solution
- Request an example when an explanation isn’t enough
- Get your solution reviewed, explain it back, and take a short quiz
Free Kit: Click here to get the Learn With Mentor AI Kit with cheat sheets, a video course, and a quiz that help you learn faster with your mentor and build the Python skills employers look for.
Take the Quiz: Test your knowledge with our interactive “Learn With Mentor AI: Working Through a Coding Exercise” quiz. You’ll receive a score upon completion to help you track your learning progress:
Interactive Quiz
Learn With Mentor AI: Working Through a Coding ExercisePractice getting unstuck on a Python coding exercise with Mentor AI, from mutable default arguments to checking for None with is.
You’ll practice all of this by working through one real exercise, Fix the Sticky Default List, step by step. Each step shows what to click, what to type, and what Mentor AI said in an example session.
Prerequisites
To follow along with this tutorial, you’ll need the following:
- A Real Python membership with Mentor AI access: The exercise you’ll use is part of a members-only course, and you need to be signed in to use Mentor AI. If you’re not a member yet, then you can start a free 7-day trial.
- Basic Python knowledge: You should know how to define a function, use a default argument, and append items to a list.
You’ll work on the Fix the Sticky Default List exercise from the Python’s None: Null in Python course. Open it in a new browser tab now so you can switch between the exercise and this tutorial.
The exercise gives you a function called add_element(). It’s supposed to append an item to the list you pass in and return that same list, so the caller’s own list changes too. If you don’t pass a list, then it should start with a new, empty one. Here’s the starter code that you’ll see in the editor:
def add_element(new_elem, starter_list=[]):
"""Append new_elem to starter_list and return the list."""
starter_list.append(new_elem)
return starter_list
Here’s what happens when you call this function twice without passing a list. You don’t need to run these calls yourself. They just show the bug:
>>> add_element(1)
[1]
>>> add_element(2)
[1, 2]
The second call should return [2], but the 1 from the first call is still there. That’s the bug, and your job is to fix it. If you already know how, that’s fine. Follow the steps anyway to see how Mentor AI can help you.
Note: Mentor AI writes a new answer every time, so its replies won’t match the examples in this tutorial word for word. The examples come from a real session and show you what to expect.
Step 1: Run the Tests in the Coding Exercise
Before you ask for help, find out what’s wrong. Above the code editor on the exercise page, you’ll find two buttons: Reset and Run Tests. Click Run Tests without changing any code:

The Test Results panel on the right side of the page shows the outcome. Each test has a short name that describes what it checks, such as: