Read first
Task 51
Estimate the cost of a prompt
Models bill per token, and a rough rule of thumb is one token per four characters. Estimating before you call the API is how a prototype stays inside its budget.
Task
Task: Estimate the cost of a prompt. What does this program print?
The editor already contains a starting point. Change it until every check passes — the Next task button unlocks when it does.
What you start with
prompt = "Write a short admission message for a coding academy in Faisalabad."
characters = len(prompt)
tokens = characters / 4
cost = tokens / 1000 * 0.002
print("Characters:", characters)
print("Tokens:", tokens)
print("Cost:", round(cost, 6))
Python
1 automatic check Capstone: the pieces of an agent
Code editor
Ctrl + Enter runs
Run your code to see the output and the checks.
Your result
Submit your code to see results
Write your code in the middle column and press Run code.
Next task (pass every check first)
Hint
Ask yourself: Task: Estimate the cost of a prompt. What does this program print?