Dec-10-2021, 09:21 AM
(This post was last modified: Dec-10-2021, 02:44 PM by Yoriz.
Edit Reason: Added code tags
)
Hi Guys
Hope you can help me with an error I don't understand.
I have the following code snippet which throws an error I don't understand:
Hope you can help me with an error I don't understand.
I have the following code snippet which throws an error I don't understand:
#Class definition of an object class Agent(): #Constructor for the class def __init__(self): self.percepts = [] self.action = 'NoOp' #a function which is supposed to take a tuple, use it as a dict key to look up the associated value def agentprogram(percept:tuple): table = {((('A','Clean'),('B','Clean')),'A'):'NoOp', ((('A','Clean'),('B','Clean')),'B'):'NoOp', ((('A','Clean'),('B','Dirty')),'A'):'Right', ((('A','Clean'),('B','Dirty')),'B'):'Suck', ((('A','Dirty'),('B','Clean')),'A'):'Suck', ((('A','Dirty'),('B','Clean')),'B'):'Left', ((('A','Dirty'),('B','Dirty')),'A'):'Suck', ((('A','Dirty'),('B','Dirty')),'B'):'Suck', } action = table[percept] return action #creating the tuple I will pass agent_percept = ((('A','Clean'),('B','Dirty')),'B') #instantiating an object of the class Agent agent= Agent() #passing the tuple and expect to get an action in return result = agent.agentprogram(agent_percept)This last line throws the following error:
Error:TypeError: agentprogram() takes 1 positional argument but 2 were given
I don't get it. I'm passing a single tuple as the function argument. Why is the compiler saying I passed 2 parameters?