Bird
0
0

The following code is intended to collect search results and summarize them, but it raises an error. What is the error?

medium📝 Debug Q14 of 15
Agentic AI - Real-World Agent Applications
The following code is intended to collect search results and summarize them, but it raises an error. What is the error?
def research_agent(queries):
    summaries = []
    for q in queries:
        summary = summarize(q)
    summaries.append(summary)
    return summaries

print(research_agent(['AI', 'Machine Learning']))
AThe function research_agent has wrong indentation
BThe append is outside the loop, so only last summary is added
CThe summarize function is not defined
Dqueries should be a string, not a list
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the indentation of append

    The append statement is outside the for loop, so only the last summary is appended to summaries.
  2. Step 2: Check if summarize is defined

    Assuming summarize is defined elsewhere, the code runs but only appends one summary.
  3. Step 3: Identify the error

    The main logical error is that summaries.append(summary) should be inside the loop to collect all summaries.
  4. Final Answer:

    The append is outside the loop, so only last summary is added -> Option B
  5. Quick Check:

    Indent append inside loop to fix [OK]
Quick Trick: Check indentation of statements inside loops carefully [OK]
Common Mistakes:
  • Assuming summarize function is missing
  • Misreading indentation as correct
  • Ignoring loop scope for append

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Agentic AI Quizzes