← VCE Applied Computing U1O2

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.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

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.

Learning
Duo
Which prompt is better for an AI code generator?
Write a Python function that takes a list of marks and returns the average, rounded to 1 decimal place.Make me something to do with marks.
Matches
Make me a program for my marks.
↓
Too vague: it does not state the language, the inputs, the expected output or any constraints.
Applying
Meanings
Term
prompt
Meaning
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.
Practice
Write a Python function called grade(mark).
Testing
Gaps
: a list of student marks
Check Answer
Spots
3Output: the average mark
4Example: [80, 90] -> 95.0

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Angelfish' badge — Reef Perfectionist, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which prompt is better for an AI code generator?
A. Write a Python function that takes a list of marks and returns the average, rounded to 1 decimal place. ✓
B. Make me something to do with marks.
A good prompt names the language (Python), the input (a list of marks), the expected output (the average) and a constraint (1 decimal place).
2. A student wants JavaScript code. What should the prompt include?
A. The language name, such as 'Write a JavaScript function...' ✓
B. Nothing about the language, because the AI will always guess correctly.
If you don't state the language, the generator may pick a different one that doesn't match your requirements.
3. Which part of a prompt describes the expected output?
A. Use a function that takes a price.
B. Return the total price including 10% GST as a number. ✓
The expected output says what the code should produce or return. The second option only describes an input.
4. Which is an example input and output you could add to a prompt?
A. Example: the code should be good and work well.
B. Example: input 5 returns 120 (the factorial of 5). ✓
Giving a specific example input and its output shows the generator exactly what you expect. Vague comments don't do this.
5. Which is a constraint you could include in a prompt?
A. Do not use any external libraries and keep it under 20 lines. ✓
B. Write the code however you like.
Constraints limit how the code is written, such as libraries, length or style. They help the code meet your requirements.

Match the Pairs

Write a Python function that takes a list of marks → States the language (Python) and the input (a list of marks) so the generator knows what to produce
Do not use any external libraries. → A constraint that limits how the generator may write the code
Give an example input and output so the AI can see exactly what is expected → Example: input [70, 80, 90] should return 80.0
Refine the prompt when the first result is not right by adding the missing requirement → Update: also return 0 if the list is empty.
Make me a program for my marks. → Too vague: it does not state the language, the inputs, the expected output or any constraints.
Write a Python function to find the average. Return it. → It leaves out the input and an example, so the AI does not know what data is given or what the result should look like.

Key Term

prompt
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.

Fill in the Blanks

1. Language: Python Input: a list of student marks Output: the average mark
Hint: Type the label that names the data given to the code.
2. Language: Python Input: a list of student marks Output: the average mark
Hint: Type the label that names the result you expect back.
3. Language: Python Task: square a number Example: input 3 gives output 9
Hint: Type the word that labels a sample input and output pair.
4. Language: Python Task: find the highest mark in a list Constraint: do not use the max() function
Hint: Type the label for a rule or limit the code must follow.
5. Code missed my rules, so I will refine the prompt and add an example.
Hint: Type the verb for improving a prompt after seeing weak results.

Spot the Error

Question 1
A Language: Python
B Input: a list of marks
C Output: the average mark
D Example: [80, 90] -> 95.0
E Constraint: use no modules
Line D — 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.
Question 2
A Language: JavaScript
B Input: whatever is needed
C Output: a greeting string
D Example: 'Zoe' -> 'Hi Zoe'
Line B — 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.
Question 3
A Write a function
B Input: two numbers
C Output: the larger number
Line A — The prompt leaves out the programming language. It should say 'Write a Python function' so the generator uses the right language.
Question 4
A Language: Python
B Input: a temperature in C
C Output: temperature in F
D Constraint: any rounding is fine
Line D — A constraint should be specific. 'Any rounding is fine' gives the generator no rule to follow. It should say 'Constraint: round to 1 decimal'.
Question 5
A Language: Python
B Input: a list of words
C Output: True if n is even
D Example: 4 -> True, 7 -> False
Line B — The input description does not match the output and example, which use whole numbers like 4 and 7. It should be 'Input: a whole number n'.

Student with a class code? Join your class →