Bird
0
0

What will be the output of this code snippet that simulates agent resource check?

medium📝 Predict Output Q5 of 15
Agentic AI - Real-World Agent Applications
What will be the output of this code snippet that simulates agent resource check?
resources = {"cpu": 4, "memory": 8}
if resources["cpu"] > 2 and resources["memory"] >= 8:
    print("Resources sufficient")
else:
    print("Resources insufficient")
ANo output
BResources insufficient
CError: KeyError
DResources sufficient
Step-by-Step Solution
Solution:
  1. Step 1: Check resource values in dictionary

    CPU is 4 (greater than 2) and memory is 8 (equal to 8).
  2. Step 2: Evaluate the if condition

    Both conditions are true, so the print statement inside if runs.
  3. Final Answer:

    Resources sufficient -> Option D
  4. Quick Check:

    Condition true = "Resources sufficient" [OK]
Quick Trick: Check all conditions carefully in if statements [OK]
Common Mistakes:
  • Misreading comparison operators
  • Assuming else runs when conditions are true
  • Confusing key names in dictionary

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes