Bird
0
0

What will this code print?

medium📝 Predict Output Q5 of 15
Agentic AI - Real-World Agent Applications
What will this code print?
tasks = ["email", "calendar", "notes"]
agent = {task: True for task in tasks}
print(agent)
A{"email": True, "calendar": True, "notes": True}
B["email", "calendar", "notes"]
C{"email": False, "calendar": False, "notes": False}
DError: invalid syntax
Step-by-Step Solution
Solution:
  1. Step 1: Understand dictionary comprehension

    The code creates a dictionary with keys from the list and values set to True.
  2. Step 2: Check the print output

    The printed dictionary shows each task mapped to True.
  3. Final Answer:

    {"email": True, "calendar": True, "notes": True} -> Option A
  4. Quick Check:

    Dict comprehension output = keys with True values [OK]
Quick Trick: Dict comprehension maps keys to values simply [OK]
Common Mistakes:
  • Confusing list and dict output
  • Setting values incorrectly
  • Syntax errors in comprehension

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes