Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Puzzling error
#2
This
result = agent.agentprogram(agent_percept)
calls
Agent.agentprogram(agent, agent_percept)
2 arguments.

An easy way to figure out these kinds of problems is adding a print.
    def agentprogram(percept:tuple, *args, **kvargs):
        print('agentprogram arguments', percept, args, kvargs)
When I run this it prints
Output:
agentprogram arguments <__main__.Agent object at 0x000002C18ADB8400> (((('A', 'Clean'), ('B', 'Dirty')), 'B'),) {}
2 arguments.
There are three ways to solve this problem. Correct agentprogram() to have "self" as the first argument, correct agentprogram() to have cls as the first argument, get rid of the Agent class.

This works and it is easy
    def agentprogram(self, percept:tuple):
But I don't think it is a good solution. Agent is not a class. Maybe the problem is that you snipped away all the important parts of Agent to make a short example for your post. If so, then use the suggested solution above. If not, look at the Agent class and tell me what it is. The __init__() creates two instance variables, but neither of these are used. The agentprogram() method doesn't use any instance variables. This could be turned into a class method (use @classmethod decorator), but it doesn't use any class variables either. Agent is a useless class wrapper around the agentprogram() function.
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')
result = agentprogram(agent_percept)
print(result)
Reply


Messages In This Thread
Puzzling error - by PythonNewbee - Dec-10-2021, 09:21 AM
RE: Puzzling error - by deanhystad - Dec-10-2021, 05:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Puzzling import issue that I have no idea how to solvr starseeker 3 1,525 Feb-21-2024, 05:07 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020