Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a simple AI agent class.
Agentic AI
class Agent: def __init__(self, name): self.name = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'agent' instead of 'name' as the value.
Using 'self' which is the instance, not the parameter.
✗ Incorrect
The agent's name is set by assigning the parameter 'name' to the instance variable self.name.
2fill in blank
mediumComplete the code to make the agent perform an action.
Agentic AI
class Agent: def act(self, task): print(f"Agent [1] is performing: {task}")
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'task' instead of the agent's name.
Using 'name' which is not defined in this method.
✗ Incorrect
The agent's name is stored in self.name, which is used to identify the agent in the print statement.
3fill in blank
hardFix the error in the agent's decision method to return the correct action.
Agentic AI
class Agent: def decide(self, options): best_option = max(options, key=lambda x: x['score']) return best_option[1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation which does not work for dictionaries.
Returning the score instead of the action.
✗ Incorrect
The best option is a dictionary, so to get the action, use best_option['action'].
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps tasks to their priorities if priority is above 5.
Agentic AI
tasks = ['clean', 'cook', 'shop'] priorities = {'clean': 7, 'cook': 4, 'shop': 9} high_priority = {task: priorities[task] for task in tasks if priorities[task] [1] [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causing wrong filtering.
Using 7 instead of 5 as the threshold.
✗ Incorrect
We want tasks with priority greater than 5, so use '>' and 5.
5fill in blank
hardFill all three blanks to create a dictionary of task names in uppercase mapped to their priority if priority is less than 8.
Agentic AI
tasks = ['read', 'write', 'code'] priorities = {'read': 6, 'write': 8, 'code': 7} filtered_tasks = {task[1]: priorities[task] for task in tasks if priorities[task] [2] [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using .lower() instead of .upper() for task names.
Using '>' instead of '<' for filtering priorities.
✗ Incorrect
We convert task names to uppercase with .upper(), and filter priorities less than 8 using '<' and 8.
