← VCE Software Development U3O1

Writing a prompt to generate code

A clear AI request stating the language, the task, the inputs and outputs, and the constraints. Keep to one task per prompt, e.g. Write a Python function that returns an average.

Understanding Writing a prompt to generate code in VCE Software Development U3O1

What it does: These lines set limits on the solution (no libraries) and define behaviour for an edge case (empty list), which are requirement and constraint statements. The words 'Python function' name the language, and the prompt also gives the function name, one task and the input, so it shows the language being specified. Naming the language and version means the AI uses syntax and libraries that match your environment. Example inputs and outputs show the AI exactly what result you expect, so it is less likely to guess wrongly. Asking for one task at a time gives code that is easier to read, test and fix. You can build the full program in steps.

Common mistakes: The output is vague. A good code prompt says exactly what comes out, for example 'Output: average as a float.'. The prompt does not name the programming language. It should say 'Write a Python function that' so the AI does not guess.

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 178–193) and word search (Modules 168–193).

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 getting usable code from an AI tool?
Write a Python 3 function that returns the average of a list of numbers.Make me something that works with numbers.
Matches
Write some code that does stuff with numbers.
↓
The prompt is vague: it has no language, no clear task, no inputs or outputs, and no constraints.
Applying
Meanings
Term
code prompt
Meaning
A clear AI request stating the language, the task, the inputs and outputs, and the constraints. Keep to one task per prompt, e.g. Write a Python function that returns an average.
Practice
Write a Python 3 function called average that takes a list of numbers and returns their mean. Example: [2, 4, 6] returns 4.0. Do not use any imports.
Testing
Gaps
Write a function
Check Answer
Spots
3Input: a list of numbers.
4Output: something useful.

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

The 'Barreleye Fish' badge — Clear Vision, 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 getting usable code from an AI tool?
A. Write a Python 3 function that returns the average of a list of numbers. ✓
B. Make me something that works with numbers.
A good code prompt names the language, states the task and says what the function takes and returns. The vague prompt does none of these.
2. Which part of a prompt names the language and version?
A. Write a function that is really good...
B. Using Python 3.12, write a function... ✓
Naming the language and version means the AI uses syntax and libraries that match your environment.
3. Which prompt gives example inputs and outputs?
A. Write a Python function is_even(n). For example, is_even(4) returns True and is_even(7) returns False. ✓
B. Write a Python function is_even(n) that does the right thing.
Example inputs and outputs show the AI exactly what result you expect, so it is less likely to guess wrongly.
4. Which prompt follows the 'one task per prompt' guideline?
A. Write a Python function that validates an age is between 0 and 120. ✓
B. Write a Python program with a login screen, a database, a validation function, a report and a file saver.
Asking for one task at a time gives code that is easier to read, test and fix. You can build the full program in steps.
5. Which prompt states a constraint?
A. Write a Python function to sort a list.
B. Write a Python function to sort a list without using the built-in sorted() or .sort(). ✓
Constraints are rules the code must follow, such as banned functions, a style or a limit on length. Stating them in the prompt avoids code you cannot use.

Match the Pairs

Write a Python 3.12 function that returns the average of a list of numbers. → A prompt that names the language and version, states one task, and describes the input (a list) and the output (an average).
Example: average([2, 4, 6]) should return 4.0 → An example input and expected output added to a prompt so the AI knows exactly what the code must do.
A prompt should state constraints, such as which features to use or avoid and how to handle bad input. → Do not use any libraries. If the list is empty, return 0.
A prompt should name the language so the AI generates code in the right language. → Write a Python function called get_total that adds up a list of prices.
Write some code that does stuff with numbers. → The prompt is vague: it has no language, no clear task, no inputs or outputs, and no constraints.
Write a Python program that reads a file, sorts the lines, validates the data, and draws a graph. → It asks for several tasks in one prompt instead of one task per prompt.

Key Term

code prompt
A clear AI request stating the language, the task, the inputs and outputs, and the constraints. Keep to one task per prompt, e.g. Write a Python function that returns an average.

Fill in the Blanks

1. Write a Python function that returns the average of a list.
Hint: Type the programming language the AI must write the code in.
2. Write a Python function that returns the average of a list of numbers.
Hint: Type the data structure that the function takes as its input.
3. Example input: [2, 4, 6] Example output: 4.0
Hint: Type the word for what the function gives back in the example.
4. Write a Python function to average a list. Constraint: return 0 if the list is empty.
Hint: Type the condition of the list that the constraint must handle.
5. Python 3: write one function that finds the largest number in a list.
Hint: Type the number of tasks a good prompt should ask for.

Spot the Error

Question 1
A Write a Python 3 function to
B find the average of a list.
C Input: a list of numbers.
D Output: something useful.
Line D — The output is vague. A good code prompt says exactly what comes out, for example 'Output: average as a float.'
Question 2
A Write a function that
B returns the largest number.
C Input: [3, 9, 2]
D Output: 9
Line A — The prompt does not name the programming language. It should say 'Write a Python function that' so the AI does not guess.
Question 3
A Write a Python 3 function to
B counts vowels and saves a CSV
C Input: 'banana'
D Output: 3
Line B — This line asks for two tasks (count vowels and save a CSV). A good prompt has one task, so it should be 'counts vowels in a string.'
Question 4
A Write a Python function that
B returns the average of nums.
C Example: [2, 4, 6] gives 9.0
D Do not use any libraries.
Line C — The example output is wrong. The average of 2, 4 and 6 is 4.0, so the example would mislead the AI.
Question 5
A Write a Python 3 function to
B check if a password is valid.
C Input: string; output: bool
D Make the rules strong enough.
Line D — The constraint is vague and cannot be measured. It should state a specific requirement, such as 'Must be 8+ characters long.'

Student with a class code? Join your class →