The function shout converts text to uppercase and adds three exclamation marks.
Step 2: Apply the function to 'hello'
Calling shout('hello') returns 'HELLO!!!'. Since tool.func points to shout, tool.func('hello') does the same.
Final Answer:
'HELLO!!!' -> Option A
Quick Check:
shout('hello') = 'HELLO!!!' [OK]
Hint: Check function logic and apply input to predict output [OK]
Common Mistakes:
Ignoring uppercase conversion
Missing exclamation marks
Assuming func is not callable
4. You wrote this custom tool but get an error when using it. What is the likely problem?
def add_numbers(a, b):
return a + b
tool = Tool(name='adder', description='Add two numbers', func=add_numbers)
result = tool.func(5)
medium
A. Tool name must be unique
B. Function add_numbers should not return a value
C. Missing one argument when calling tool.func
D. Description is too short
Solution
Step 1: Check function parameters
add_numbers requires two inputs: a and b.
Step 2: Check how tool.func is called
tool.func(5) provides only one argument, causing an error for missing the second argument.
Final Answer:
Missing one argument when calling tool.func -> Option C
Quick Check:
Function needs 2 args, only 1 given [OK]
Hint: Match function parameters with call arguments [OK]
Common Mistakes:
Ignoring function argument count
Thinking description length causes error
Assuming tool name uniqueness causes runtime error
5. You want to build a custom tool that summarizes text by returning the first 10 words. Which code correctly defines this tool's function?
hard
A. def summarize(text):
return ' '.join(text.split()[:10])
B. def summarize(text):
return text[:10]
C. def summarize(text):
return text.split()[-10:]
D. def summarize(text):
return len(text.split())
Solution
Step 1: Understand the goal of the function
The function should return the first 10 words, not characters or last words.
Step 2: Analyze each option
def summarize(text):
return ' '.join(text.split()[:10]) splits text into words and joins the first 10 words correctly. def summarize(text):
return text[:10] returns first 10 characters, not words. def summarize(text):
return text.split()[-10:] returns last 10 words. def summarize(text):
return len(text.split()) returns word count, not summary.
Final Answer:
def summarize(text):
return ' '.join(text.split()[:10]) -> Option A
Quick Check:
First 10 words = def summarize(text):
return ' '.join(text.split()[:10]) [OK]
Hint: Split text and join first 10 words for summary [OK]
Common Mistakes:
Returning characters instead of words
Taking last words instead of first
Returning word count instead of summary
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.