Bird
0
0

What will be the output of the following Python code?

medium📝 Predict Output Q4 of 15
Agentic AI - Agent Observability
What will be the output of the following Python code?
response = {'usage': {'prompt_tokens': 60, 'completion_tokens': 40, 'total_tokens': 100}}
tokens = response['usage']['total_tokens']
print(f"Tokens used: {tokens}")
ATokens used: 60
BTokens used: 100
CTokens used: 40
DKeyError
Step-by-Step Solution
Solution:
  1. Step 1: Access 'total_tokens'

    The code accesses response['usage']['total_tokens'], which is 100.
  2. Step 2: Print statement

    The print outputs the string with the value 100 inserted.
  3. Final Answer:

    Tokens used: 100 -> Option B
  4. Quick Check:

    Check dictionary keys carefully; no error expected. [OK]
Quick Trick: Access exact key 'total_tokens' to get total tokens. [OK]
Common Mistakes:
  • Using wrong key causing KeyError
  • Confusing prompt or completion tokens with total
  • Misreading the print output format

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes