0
0
Prompt Engineering / GenAIml~20 mins

Token counting and cost estimation in Prompt Engineering / GenAI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Token Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding token counting in text inputs
If a text input contains the sentence:
"Hello world! How are you today?"
How many tokens would a typical tokenizer count for this sentence?
A8 tokens
B6 tokens
C5 tokens
D7 tokens
Attempts:
2 left
💡 Hint
Think about how punctuation and spaces are usually split into tokens.
Predict Output
intermediate
2:00remaining
Calculate token cost for a prompt
Given a prompt with 150 tokens and a model charging $0.002 per 1,000 tokens, what is the cost for processing this prompt?
A$0.03
B$0.0003
C$0.00015
D$0.003
Attempts:
2 left
💡 Hint
Calculate cost by multiplying tokens by price per token.
Model Choice
advanced
2:00remaining
Choosing a model based on token limits
You have a text input of 12,000 tokens. Which model should you choose if Model A supports up to 8,000 tokens and Model B supports up to 16,000 tokens?
AEither model works
BModel A
CModel B
DNeither model works
Attempts:
2 left
💡 Hint
Check the maximum token limit for each model.
Metrics
advanced
2:00remaining
Estimating total cost for multiple API calls
You make 3 API calls with token usage: 500, 1,200, and 2,300 tokens. The cost is $0.0015 per 1,000 tokens. What is the total cost?
A$0.0075
B$0.009
C$0.0069
D$0.006
Attempts:
2 left
💡 Hint
Sum tokens first, then multiply by cost per token.
🔧 Debug
expert
2:00remaining
Identify the error in token cost calculation code
What error does this code produce?
tokens = 1200
price_per_1000 = 0.002
cost = tokens * price_per_1000
print(f"Cost: ${cost}")
Prompt Engineering / GenAI
tokens = 1200
price_per_1000 = 0.002
cost = tokens * price_per_1000
print(f"Cost: ${cost}")
APrints Cost: $2.4
BPrints Cost: $0.0024
CSyntaxError due to f-string
DTypeError due to division
Attempts:
2 left
💡 Hint
Check the order of operations and units in the formula.