Prompts for Coding
AI coding assistants are most useful when you give them the language, the goal, the code and the exact error.
The Coding Prompt Checklist
| Include | Why |
|---|---|
| Language and version | Python 3, JavaScript, PHP... the code differs |
| What the code should do | The goal, with an example input and output |
| Your existing code | So the AI fits its answer to it |
| The full error message | The exact text, not "it doesn't work" |
| Limits | "No extra libraries", "beginner-friendly", "keep my variable names" |
Writing New Code
Example
Write a Python function called grade(marks) that returns
"A" for 80 and above, "B" for 65-79, "C" for 50-64 and "F" below 50.
Add 3 example calls with their expected results. No libraries.A good reply might look like this, and you should run it yourself:
Example
def grade(marks):
if marks >= 80:
return "A"
elif marks >= 65:
return "B"
elif marks >= 50:
return "C"
return "F"
print(grade(85), grade(70), grade(42))A B F
Fixing an Error
Paste the code and the full error:
Example
My Python code crashes. Explain the cause in simple words
and show the fixed line only.
Code:
price = input("Price: ")
total = price * 2 + 50
Error:
TypeError: can only concatenate str (not "int") to strThe AI should explain that input() returns text, so it must be converted with int() or float():
Example
price = int("120") # in the real program: int(input("Price: "))
total = price * 2 + 50
print(total)290
Explaining Code
Example
Explain this code line by line for a beginner.
Then tell me one way it could break.
for i in range(1, 6):
print(i * "*")Reviewing and Improving
Example
Act as a senior Python developer. Review my function for bugs,
unclear names and missing edge cases. Give a numbered list of
issues, most important first. Do not rewrite it yet.Then follow up: "Now fix issues 1 and 2 only."
Asking for Tests
Example
Write 5 test cases for my grade() function, including the edge
values 49, 50, 79 and 80. Show each input and expected output.Edge values are where most bugs hide.
Safe Habits with AI Code
- Run and test everything. AI code can look right and still be wrong.
- Understand it before you submit or deploy it. You are responsible for it.
- Never paste secrets: remove API keys, passwords and database URLs before sharing code.
- Check packages: AI sometimes suggests libraries or functions that do not exist. Look them up.
- Ask for small pieces: one function at a time is easier to check than a whole app.
Coding assistants inside editors (like VS Code) can read your project files. Give them clear instructions, review every change before accepting it, and keep your code in Git so you can undo mistakes.
Exercise
Exercise
Your code shows an error. What should your prompt include?
