Sub topic 5
Prompts that ask for hints and explanations
This chapter assumes you can write and run small Python functions, you have used a chat-based AI assistant, and you know the attempt-first workflow from the previous chapter. Here you will learn how to word a request so the AI supports your thinking instead of replacing it.
Why the wording of a prompt matters
An AI assistant answers the question you ask. If you write "write a function that returns the median of a list", you get a finished function. The code may be correct, but you did none of the work, so you learn little.
A prompt is also a way to set the AI's role. In the chapter on roles, you chose between tutor, reviewer and generator. The prompt is where you make that choice. A good learning prompt does three things:
- It shows your own attempt, so the AI answers your problem and not a generic one.
- It states what you want back: a question, a hint, an explanation or a review.
- It states what you do not want, usually the full solution.
Anatomy of a tutoring prompt
Here is a template for a stuck moment. Replace the placeholder with your code and the error or wrong output.
I am learning Python. I tried to write a function that returns the median of a list, and my code is below.
<paste your code and the error or wrong output>
Do not give me the full solution. First, ask me one question that helps me find the problem. If I am still stuck, give a hint. After I fix it, review my code and tell me what to improve.Each part has a job:
| Part of the prompt | What it does |
|---|---|
| "I am learning Python" | Sets the level of the explanation. |
| Your code and the error | Gives the AI evidence about your attempt. |
| "Do not give me the full solution" | Sets a boundary on the answer. |
| "First, ask me one question" | Makes you reason before you get help. |
| "If I am still stuck, give a hint" | Lets help increase in steps. |
| "After I fix it, review my code" | Adds feedback once you have done the work. |
Ask for help in steps
The template asks for help in a fixed order. This is a ladder of support, and you climb one rung at a time.
The last rung is a worked example on a different problem. That keeps the transfer work with you: you must apply the idea to your own code.
Prompts for explanation
Sometimes you do not need a hint. You need to understand code that already exists. Useful phrasings:
- "Explain this line by line, and name the Python feature each line uses."
- "I think this loop stops early because of the
returninside it. Is my reasoning right? Do not rewrite the code." - "Explain
sorted()with an example that is not about medians."
The second example is the strongest. It states your hypothesis first, so the AI checks your reasoning instead of replacing it.
Practice with prediction
You can also ask the AI to quiz you. First try this function yourself.
def count_vowels(text):
return sum(1 for ch in text.lower() if ch in "aeiou")
# Predict the output before you run this line.
print(count_vowels("Learning with AI"))Write down your prediction before you run it. The expected result is 6. If your output differs from your prediction, find the reason before you ask the AI. If you cannot, use this prompt: "My prediction was X and the output was Y. Ask me questions until I find the reason."
Common errors
- Pasting only the error. The AI cannot see your reasoning. Include your code and what you expected.
- Forgetting the boundary. Without "do not give me the full solution", many assistants will give it anyway. Repeat the boundary if the answer drifts.
- Accepting a hint you do not follow. If a hint is unclear, say so and ask for a different one. Do not copy it.
- Asking for too many things at once. One question per step keeps the help small.
Exercise
Rewrite this prompt so it asks for a hint and not a finished answer: "Fix my median function." Name at least three things your new prompt includes.
Show answer
A good rewrite is: "I am learning Python. My median function returns the wrong value for [4, 1, 3, 2]. My code is below: <code>. Do not give me the full solution. Ask me one question that helps me find the problem, and give a hint only if I am still stuck." It includes the learner's level, the code and the wrong output, a boundary against the full solution, and a stepwise order of help.