The function returns the first 10 characters of the text plus '...'. The slice text[:10] takes characters at positions 0 to 9.
Step 2: Extract the first 10 characters from the input
'Artificial intelligence helps research.' first 10 chars are 'Artificial ' (including the space at position 9). So the output is 'Artificial ...'.
Step 3: Confirm the exact output
The output is 'Artificial ' + '...' = 'Artificial ...', which matches Artificial i... 'Artificial i...'. Actually, the 10 characters are 'Artificial ' (9 letters + 1 space), so the output is 'Artificial ...'. Artificial i... shows 'Artificial i...', which includes the 'i' from 'intelligence' (11th character). So Artificial i... is incorrect.
Step 4: Check options carefully
Artificial... is 'Artificial...', which is 9 letters + '...'. Artificial i... is 'Artificial i...', which is 10 letters + '...'. The code returns text[:10] + '...', so 10 characters plus '...'. The first 10 characters are 'Artificial ' (with space), so the output is 'Artificial ...'. None of the options exactly match 'Artificial ...'.
Step 5: Correct the options or answer
Since none of the options exactly match 'Artificial ...', the closest is Artificial i... 'Artificial i...', which is 11 characters before '...'. So the correct answer should be Artificial... 'Artificial...', which is 9 letters + '...'. But the code returns 10 characters + '...'. So the correct answer is Artificial i....
Final Answer:
Artificial i... -> Option D
Quick Check:
text[:10] + '...' = 'Artificial i...' [OK]
Hint: Count characters carefully including spaces for slicing [OK]
Common Mistakes:
Counting 10 letters without space
Assuming slice excludes space
Confusing slice length with index
4. 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']))
medium
A. The function research_agent has wrong indentation
B. The append is outside the loop, so only last summary is added
C. The summarize function is not defined
D. queries should be a string, not a list
Solution
Step 1: Analyze the indentation of append
The append statement is outside the for loop, so only the last summary is appended to summaries.
Step 2: Check if summarize is defined
Assuming summarize is defined elsewhere, the code runs but only appends one summary.
Step 3: Identify the error
The main logical error is that summaries.append(summary) should be inside the loop to collect all summaries.
Final Answer:
The append is outside the loop, so only last summary is added -> Option B
Quick Check:
Indent append inside loop to fix [OK]
Hint: Check indentation of statements inside loops carefully [OK]
Common Mistakes:
Assuming summarize function is missing
Misreading indentation as correct
Ignoring loop scope for append
5. You want to build a research assistant agent that searches multiple sources and summarizes results. Which approach best improves accuracy and efficiency?
hard
A. Use multiple search APIs, combine results, then summarize with a language model
B. Search only one source deeply and summarize without combining
C. Summarize each source separately and do not merge results
D. Collect raw data without summarizing to avoid errors
Solution
Step 1: Consider combining multiple sources
Using multiple search APIs gathers diverse information, improving coverage and accuracy.
Step 2: Summarize combined results with a language model
Combining results before summarizing helps create a concise, comprehensive summary efficiently.
Final Answer:
Use multiple search APIs, combine results, then summarize with a language model -> Option A
Quick Check:
Combine sources + summarize = best accuracy [OK]
Hint: Combine diverse data before summarizing for best results [OK]