Lesson 2 — Writing a clear coding prompt
Say exactly what you want
A prompt is the message you send to the assistant. A vague prompt ("write a vowel thing") gets a vague answer. A clear coding prompt has four parts:
- Goal — what the code must do, in one sentence.
- Context — who you are and what you use ("beginner, Python 3.12, standard library only").
- Constraints — the rules: function name, inputs, what to avoid.
- Example — one input and the exact output you expect.
Goal: Write a Python function that counts vowels in a string.
Context: I am a beginner. I use Python 3.12.
Constraints:
- Name it count_vowels(text)
Example: count_vowels("Hello") returns 2
The example is the most useful part: it removes guessing, and later it becomes your first test.
Why it matters: the assistant only knows what you write. Two extra lines of context save ten minutes of fixing the wrong answer.
Want it another way?
Task
Finish build_prompt(): after the Goal line add "Context: ...", a "Constraints:" line with each constraint as "- ...", and "Example: ...".
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.