Complete the code to define an autonomous agent class with a method to act independently.
class AutonomousAgent: def __init__(self, name): self.name = name def [1](self): return f"{self.name} is acting on its own decisions."
The method act clearly represents the agent performing actions independently.
Complete the code to add a semi-autonomous agent method that requires human input.
class SemiAutonomousAgent: def __init__(self, name): self.name = name def [1](self, command): return f"{self.name} executes command: {command}"
The method execute fits well for a semi-autonomous agent that acts on commands.
Fix the error in the code to correctly check if an agent is autonomous.
def is_autonomous(agent): if agent.[1] == 'act': return True else: return False
The attribute to check should be the method name 'act' to identify autonomous agents.
Fill both blanks to create a dictionary comprehension that maps agent names to their action methods.
agents = [autonomous_agent, semi_autonomous_agent]
actions = {agent.[1]: agent.[2] for agent in agents}The keys should be agent names and the values their 'act' methods for autonomous agents.
Fill all three blanks to define a function that calls the correct method based on agent type.
def perform_action(agent, command=None): if hasattr(agent, '[1]'): return agent.[1]() elif hasattr(agent, '[2]') and command is not None: return agent.[2]([3])
The function checks if the agent has 'act' method for autonomous action, else uses 'execute' with the given command.