AI Computer Science Academy · Faisalabad

AI & Prompt Engineering

Estimate the cost of a prompt

Task 51 of 56 Python Capstone: the pieces of an agent
All tasks
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.

Checks on this task:

  • Check 1

Track progress

0 of 56 tasks complete

Next task unlocks when every check passes.

Sign in to keep your code and certificates.

Next task (pass every check first)