Sub topic 5
Prompts that Ask for Hints and Explanations
This chapter covers how to write prompts that get hints, explanations and review from an AI assistant instead of finished answers. It assumes you can write small Python functions, run a script in a terminal, and have used a chat assistant before. It builds on the attempt-first workflow from the previous chapter: you try the problem, then you ask.
Why the prompt decides what you learn
An AI assistant tries to be helpful, and by default it treats "helpful" as "complete the task." If you paste an error message and write "fix this," you will usually get corrected code. The code may work, but you did none of the reasoning that would help you fix the next bug yourself.
Your prompt sets the role the AI plays and the amount of work you keep. A prompt can ask for a full solution, an explanation, a hint, or a review. Each one leaves you with a different amount of thinking to do.
| Prompt style | Example | What you keep |
|---|---|---|
| Request for a solution | "Write a median function." | Nothing. You receive a result. |
| Request for an explanation | "Why does my loop skip the last item?" | Some. You read the reasoning and apply it. |
| Request for a hint | "Give me a hint about why my loop skips the last item." | Most. You still find and write the fix. |
| Request for a question | "Ask me one question that helps me find the bug." | Nearly all. You form the hypothesis. |
| Request for a review | "Review my working code and suggest improvements." | All of the solving. You get feedback afterward. |
Moving down the table gives you more practice and gets you to a working answer more slowly. That cost is intended.
The parts of a good learning prompt
A prompt that gets you useful help has five parts.
- Your goal. State what the code should do, in one sentence.
- Your attempt. Paste your code. If you have not tried yet, go back and try first.
- The evidence. Include the exact error message, or the input, the expected output and the actual output.
- Your current thinking. Say what you believe is wrong, even if you are unsure.
- The help you want and the help you do not want. Name the form of help (question, hint, explanation, review) and rule out the form you want to avoid.
Part 4 is the one learners skip most often. Writing "I think the problem is in the loop bounds because it works for two items but not three" forces you to form a hypothesis. It also lets the AI correct your model instead of replacing your code.
Here is the template from this tutorial's plan, which combines all five parts:
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.Notice the order it sets up. The AI asks, then hints, and only reviews after you have fixed the problem yourself. You can reuse this structure for other tasks by changing the first sentence.
A ladder of hints
A single request for "a hint" can mean very different things. It helps to think of hints as a ladder and to climb one rung at a time.
- A question. "What value does
midhave when the list has four items?" - A location. "Look at the line that handles the even-length case."
- A concept. "Think about what the median is when there is no single middle item."
- A pointed hint. "For an even-length list, you need to combine two items, not pick one."
- A partial example. A similar problem solved, or one line of pseudocode.
- The full solution. The last resort, and one you should then study line by line.
You can build the ladder into your prompt:
Give me hints one rung at a time. Start with a question only. Wait for my reply before moving to the next level. The levels are: question, location of the problem, the concept involved, a pointed hint, a similar example. Do not show the solution unless I write "show solution".The phrase "wait for my reply" matters. Without it, many assistants will give every level in one message, and you will read the answer before you have tried anything.
Asking for explanations without losing the work
Explanations are not bad. Reading a clear explanation of how sorted or integer division works is a good use of an AI. The risk is passive reading: an explanation feels clear while you read it, and you may not be able to reproduce it later.
Three habits keep explanations active.
Predict first. Before asking what some code does, write down what you think it does. Then ask the AI to compare your prediction with the real behavior. This turns the answer into feedback on your own model. Take this short function:
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 your expected result first. The string has the vowels e, a, i, i, A and I once lowercased, so you should expect 6. If your prediction differs from the output, do not ask for the answer. Ask: "My prediction was X and the output was Y. Ask me questions that help me find where my understanding differs."
Ask for the why, not just the what. "What does len(ordered) // 2 do?" gets a description. "Why is // used here instead of /?" gets a reason, and reasons transfer to new problems.
Request a check on yourself. End an explanation request with: "Then give me two short questions to test whether I understood, and do not show the answers until I reply." This is retrieval practice, which you met earlier, built into the prompt.
Asking for review
Review is the safest way to get a complete answer from an AI, because the solving has already happened. Make the request specific. "Is this good?" gets generic praise. A better prompt names the criteria:
Here is my working median function. Review it for: (1) inputs it handles incorrectly, (2) naming and readability, (3) anything in it that I should be able to explain but might not understand. Point out problems and explain them. Do not rewrite the function. I will make the changes myself.The last two sentences stop the AI from replacing your code. If it does replace your code, ask it to describe the change in words and make the edit yourself.
You can also use review to find edge cases you missed. Consider the finished function below, which resembles what an AI might produce:
def median(values):
if not values:
raise ValueError("median() requires at least one value")
ordered = sorted(values)
mid = len(ordered) // 2
if len(ordered) % 2 == 1:
return ordered[mid]
return (ordered[mid - 1] + ordered[mid]) / 2
assert median([3, 1, 2]) == 2
assert median([4, 1, 3, 2]) == 2.5
assert median([5]) == 5
try:
median([])
except ValueError:
pass
else:
raise AssertionError("median([]) should raise ValueError")A good review prompt for this code is: "List the input cases my tests do not cover, as questions. Do not answer them." You might get questions about lists with repeated values, negative numbers, or input that is not a list at all. You then decide which matter and write the tests.
Common mistakes in learning prompts
- Pasting the assignment text only. Without your attempt, the AI has nothing to react to, so it produces a solution. Include your code.
- Asking vague questions. "Why doesn't this work?" with no error or expected output leads to guessing, and the AI may rewrite everything.
- Not stating the boundary. If you do not say "no full solution," assume you may get one.
- Letting the conversation drift. In a long chat, the AI may stop following your original rule and start giving code. Restate the rule: "Reminder: hints only, no code."
- Accepting a hint you do not understand. If you cannot restate a hint in your own words, ask for the same level in a different form instead of climbing to a higher rung.
- Treating the AI's explanation as correct without checking. Explanations can contain errors. Run small experiments in a REPL (an interactive prompt where you type code and see results immediately) to confirm claims.
Keeping the rule in place
If you use the same boundaries every session, you can store them once. Many assistants allow a saved instruction, a system prompt, or a custom persona. A short version:
Act as a Python tutor for an intermediate learner. Default to questions and hints, one at a time. Never give a full solution unless I write "show solution". When I share working code, review it and name problems without rewriting. When you explain, end with two check questions and wait for my answers.The value of this is consistency. You do not have to remember to type the rule when you are frustrated, which is exactly when you are most tempted to ask for the answer.
Summary
- The wording of your prompt determines whether you get a result or a learning step.
- A good prompt states your goal, includes your attempt and the evidence, gives your own hypothesis, and names the help you want and do not want.
- Climb the hint ladder one rung at a time, and tell the AI to wait for your reply.
- Predict before you ask, ask why instead of only what, and request check questions.
- Use review after your own solution, with named criteria and a ban on rewriting.
- Verify hints and explanations by running code, because they can be wrong.
Exercise
You wrote a function that is supposed to return the median of a list, but median([4, 1, 3, 2]) returns 3 instead of 2.5. Write a prompt, using the five parts of a good learning prompt, that asks for help without receiving the solution. Label each part.
Show answer
A good answer contains all five parts. Example: "Goal: median(values) should return the middle value of a list, or the mean of the two middle values when the length is even. Attempt: <your code>. Evidence: median([4, 1, 3, 2]) returns 3, but I expected 2.5. My thinking: I suspect the even-length case is not handled, because odd-length lists give correct results. Help wanted: first ask me one question that helps me find the problem, then give hints one level at a time and wait for my reply. Do not give me the full solution or rewrite my code." Check that your prompt includes your own code, the exact input, expected and actual outputs, a stated hypothesis, and an explicit ban on the full solution.
Exercise
Run count_vowels("Learning with AI") after writing your prediction. Suppose your prediction was 5 and the output is 6. Which of these prompts is better for learning, and why? (a) "Why is the answer 6?" (b) "I predicted 5 and the output was 6. Ask me questions that help me find where I miscounted. Do not tell me the answer."
Show answer
Prompt (b) is better. It shows your prediction, so the AI can respond to your specific mistake. It also asks for questions instead of the answer, so you do the diagnosis yourself. Prompt (a) invites a direct explanation that you would read passively. (The count is 6 because the lowercased text has the vowels e, a, i, i, a and i. Counting only the lowercase letters in "Learning with" and forgetting that "AI" contributes two more vowels gives a smaller number.)
Exercise
Write a review prompt for the finished median function that asks the AI to find untested input cases but not to answer them or rewrite the code.
Show answer
For example: "Here is my median function and my tests. List the input cases my tests do not cover, written as questions. Do not answer the questions and do not rewrite or extend my code. I will decide which cases matter and write the tests myself." The key elements are the named task (untested cases), the output format (questions), and the explicit limits on answering and rewriting.