Writing a prompt for code generation
Instructions given to an AI code generator. A good one states the language, the inputs, the expected output and any constraints so the code matches the requirements.
Understanding Writing a prompt for code generation in VCE Applied Computing U1O2
What it does: An example input with its expected output removes guesswork and lets you check that the generated code behaves correctly. Refining a prompt means adding or fixing requirements after checking the result, so the next code matches what you need. If you don't state the language, the generator may pick a different one that doesn't match your requirements. Constraints limit how the code is written, such as libraries, length or style. They help the code meet your requirements. Naming the language and the input is the start of a good prompt, because the AI then writes code in the right language for the right data.
Common mistakes: The example output must match the requirement. The average of 80 and 90 is 85.0, not 95.0. A wrong example makes the generator produce wrong code. The input is vague. A good prompt states exactly what the input is, such as 'a string, the name', so the generator knows what the function receives.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 89–124) and word search (Modules 8–124).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
promptFill in the Blanks
Spot the Error
Student with a class code? Join your class →