Working with an AI pair programmer is like having a conversation. The quality of its answers depends heavily on the quality of your questions. A well-written prompt will get you useful, relevant code and explanations. A vague or confusing prompt will lead to generic, unhelpful, or incorrect responses.
This guide will teach you how to "engineer" your prompts to get the best possible results from your AI partner. Learning this skill is a key objective of this assignment.
A good prompt gives the AI the information it needs to be a helpful partner. A simple way to remember this is with the "Four C's": Context, Clarity, Conciseness, and Constraints.
Here is how you can apply the Four C's in different situations during your project.
Your first prompt is crucial for setting the Context.
A Bad Prompt:
"how do i make a temperature thing"
A Good Prompt (using the Four C's):
[Context]: "Hello! I'm a student learning Python and I'm using a Raspberry Pi Pico with the Thonny IDE. I have a DHT11 temperature sensor connected to GP15. [Clarity]: I need to write a MicroPython script that reads the temperature and humidity from the sensor. [Conciseness]: Can you provide the basic code to do just that one thing? [Constraints]: Please include comments explaining each part of the code. Don't worry about printing to a display or saving to a file yet."
When you need a new feature, be Clear and Concise.
A Bad Prompt:
"now make it do csv"
A Good Prompt:
[Context]: "Here is my current MicroPython code:
[paste your current, working code][Clarity]: I want to write the temperature and humidity readings to a CSV file on the Pico calleddata.csv. The file should have three columns:timestamp,temperature_C, andhumidity. [Conciseness]: Can you show me how to modify my main loop to open the file, append a new line with the data, and then close it?"
When you have a bug, give the AI all the information. The error message itself is critical Context.
A Bad Prompt:
"my code is broken"
A Good Prompt:
[Context]: "I'm using a Raspberry Pi Pico and my code was working, but now it's giving me an error. Here is the full error message I see in Thonny:
[paste the complete, exact error message]. Here is the full script that is causing the error:[paste your full script]. [Clarity]: The error seems to happen on the line[mention the line number or the line of code]. I think the problem is related to converting the sensor reading to a string, but I'm not sure. [Constraints]: Can you explain what this error means and suggest two or three possible ways I could fix it?"
AI models are not perfect. They will sometimes:
- Make up facts or library names ("hallucinate").
- Give you code that doesn't run.
- Give you code that is inefficient or overly complex.
It is your job to be the human in the loop!
- Always test the code. Never assume the AI's output is correct.
- Think critically. Does the explanation make sense? Is there a simpler way to do this?
- Re-prompt if needed. If you don't get a good answer, try rephrasing your question. Add more context or be more specific. Tell the AI what was wrong with its last response.
Good luck!