Ask for a calculation
You can tell the model which module to use. Name the module, the function, and the value it should return.
Why you name the module
A circle's area is pi times the radius times the radius. Pi is not a guess such as 3.14. Python stores a fuller value as math.pi in the math module. If the prompt never names that module, the reply may invent a rough constant, or it may forget import math and then fail when it uses math.pi.
The module exists so the constant is shared and already tested. The prompt exists so the model uses that module instead of a homemade number. Ask writes the function. Run still checks it.

Name the module in the prompt. A model that is not told to use math may invent a rough value for pi.
What the prompt should include
A short prompt is enough when four facts are clear.
- The function name, such as
area. - The parameter, such as
radius. - The module,
math, and the constantmath.pi. - The value to return:
math.pi * radius * radius.
What should you name in a prompt that asks for a circle area?
Match each part of the prompt with what it tells the model.
- area
- radius
- math.pi
A worked example
Suppose you wanted circumference instead of area. Circumference is 2 * math.pi * radius. The prompt names that job in one sentence:
Ask for a function named circumference that takes a radius and returns 2 * math.pi * radius, using the math module.
A reply that followed that prompt would look like this:
- Read the reply and find
import math. - Check that the function name and parameter match the prompt.
- Check that the return expression uses
math.pi, not a rounded stand-in. - Run. If the check fails, change the prompt and ask again, or edit the line yourself.
This program cannot be stepped through.
Click the line that uses the math module's constant.
Put the lines in an order that defines circumference.
import math
return radius
def circumference(radius):
return 2 * math.pi * radius
The area prompt is the same kind of sentence: function name, parameter, module, and the product to return.
Exercise
Ask for a function named area that takes a radius and returns the area of a circle, using math.pi. The area is math.pi * radius * radius. After the reply lands, Run checks the function.
Ask for a function named area that takes a radius and returns the area of a circle, using math.pi.