Learn through a notebook dialogue

Connect ChatGPT or an API provider and use this notebook’s Learning response style. Run the Python setup and read the three saved answers as a worked dialogue. To rerun a completed question, turn off Keep answer for that cell, then work through the AI questions one at a time. The final question supplies a learner follow-up that you can revise. The original Python function remains deliberately flawed.

Learn through a notebook dialogue

Connect ChatGPT or an API provider and use this notebook’s Learning response style. Run the Python setup and read the three saved answers as a worked dialogue. To rerun a completed question, turn off Keep answer for that cell, then work through the AI questions one at a time. The final question supplies a learner follow-up that you can revise. The original Python function remains deliberately flawed.

The first question explicitly keeps its answer, the second inherits the notebook’s Keep setting, and the final question has Keep off so it can be refreshed after a correction. You can inspect and change these controls on each cell.

def count_even(
    numbers: list[int],  # Integers to inspect.
) -> int:  # Count returned by this deliberately flawed first draft.
    """Return the first draft's count so a learner can debug it."""
    return sum(value % 2 for value in numbers)


test_numbers: list[int] = [2, 4, 7]
print(f"First draft result: {count_even(test_numbers)}")
print("Expected even count: 2")
First draft result: 1
Expected even count: 2

Turn 1: ask for a hint

Run the next AI Prompt. Learning style asks the tutor to use questions and small hints rather than give the complete corrected function. Pause when its answer appears. Think about the question before writing your response below.

Help me understand why count_even([2, 4, 7]) returns 1 although there are two even numbers. Ask one diagnostic question at a time. Do not write the complete corrected function.

What does value % 2 produce for each number in [2, 4, 7]?

Turn 2: your attempt

The worked learner response below answers the tutor’s question in the learner’s own words. Read it, or replace it with your own attempt before deliberately rerunning only that prompt. The preceding completed prompt and answer become conversation history. The final prompt has a supplied follow-up and a saved answer. Edit it to try your own next question.

value % 2 is 0 for 2 and 4, and 1 for 7. So the sum counts odd numbers, not even numbers. What single change could I try, and how would I check it?

Exactly—the current expression counts odds. Try changing the expression inside sum so it tests whether the remainder is zero. Then run count_even([2, 4, 7]) and check whether it returns 2. What result do you get?

Turn 3: test a correction to the conversation

The follow-up below is supplied learner text. It proposes a check but does not claim the Python code was edited or rerun. To explore editable history yourself, double-click an earlier answer Markdown cell, correct a statement or add a note, then revise and rerun the final prompt. Current edited answer text, including unsaved changes, is used as history; save the notebook to preserve it. The final prompt has Keep answer off, so rerunning it refreshes its paired answer. If you change an earlier prompt, rerun that prompt deliberately before relying on its old answer.

Supplied worked continuation: I have not edited or rerun the Python function. I think checking whether value % 2 == 0 would count the even values, but I want to reason about it before changing code. Ask me one diagnostic question about an edge case I should predict, without writing the complete corrected function.

Before changing the code, what would your proposed check count for [0, -2, -3], and why?

What Keep means here

With notebook Keep AI answers on, a completed inherited answer survives Run All and Shift+Enter without another provider request. A blank, failed, cancelled, or deleted answer remains retryable. A cell with explicit Keep on stays protected even if you turn the notebook default off. Use Use notebook setting beside a cell checkbox to remove its explicit choice. Keep protects saved Markdown; it does not recreate Python kernel state after restart.

← Examples guide · Download this notebook