Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define an agent that makes decisions without human input.
Prompt Engineering / GenAI
class Agent: def __init__(self): self.state = None def decide(self, environment): return [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Returning None instead of an action.
Using print statements instead of returning an action.
✗ Incorrect
The agent decides by choosing the best action from the environment, enabling autonomous decisions.
2fill in blank
mediumComplete the code to update the agent's state after taking an action.
Prompt Engineering / GenAI
class Agent: def __init__(self): self.state = None def update_state(self, action): self.state = [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting state to None instead of the action.
Using print instead of assignment.
✗ Incorrect
The agent updates its internal state to the action it just took, reflecting autonomous decision-making.
3fill in blank
hardFix the error in the agent's decision method to return an action string.
Prompt Engineering / GenAI
class Agent: def decide(self): action = 'move_forward' [1] action
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of return.
Using pass which does nothing.
✗ Incorrect
The decide method must return the action string so the agent can act autonomously.
4fill in blank
hardFill both blanks to create a dictionary of actions and their rewards for autonomous decision making.
Prompt Engineering / GenAI
rewards = { 'move': [1], 'stop': [2] } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning negative reward to 'move' which discourages action.
Using None instead of numeric rewards.
✗ Incorrect
The 'move' action has a positive reward (10), encouraging the agent to move, while 'stop' has zero reward.
5fill in blank
hardFill all three blanks to create a function that selects the best action based on rewards.
Prompt Engineering / GenAI
def best_action(actions, rewards): best = None max_reward = [1] for action in actions: if rewards[action] [2] max_reward: best = action max_reward = rewards[action] return [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing max_reward to positive infinity.
Using '<' instead of '>' in comparison.
Returning None instead of best action.
✗ Incorrect
Initialize max_reward to negative infinity to find max; use '>' to compare; return best action.