'Python 3 how to use loops with classes

I'm creating a seller/buyer simulation in a tournament to see if sellers accept or reject buyers' offers.

I have made several strategies for the sellers and the buyers written as classes. Each buyer class has a offer method that returns a certain offer, and seller class has a review method that takes in the buyers offer and if it is in their 'threshold' of acceptance it gets moved to an empty array. The more full the array is the more 'accepts' happened.

I have also added id attributes to be able to follow more who is playing who in the tournament

Example of seller class:

    def __init__(self):
        self.offer_history = []
       
    def review(self, offer):
        self.offer_history.append(offer)
        return offer > twoThirdsOfPrice
    
    def idcode(self):
        self.idcode = 11 

Example of buyer class

class offerLow():        
    def offer(self):
        return (thirdOfPrice * random.random())
    
    def idcode(self):
        self.idcode = 21

I am trying to create a tournament which loops over these different strategies so every seller plays every offerer. Here is the tournament so far. I've been getting errors like

offer() missing 1 required positional argument: 'self'

and think theres something I've misunderstood on how to get this loop to work.

offerer_strategies = [offerLow, offerMed, offerHigh, randomLowerHalf, alwaysHalf, lowButReasonable, luckTester, 
                      takeTheAverage]

seller_strategies = [acceptLow, acceptMed, acceptHigh, averageHuman]

outcomes = []

n=0

for offerer in offer_strategies:
    for seller in seller_strategies:
        n+=1
        offerer = offerer_strategies[n]
        seller = seller_strategies[n]
        score = sum(seller.review(offerer.offer()) for _ in range(500))
        outcomes.append(concat(seller.idcode, offerer.idcode), score)


Solution 1:[1]

Your class offerLow has two instance method offer and idcode but does not have __init__ method to initialize an instance. You can add @staticmethod decorator to make your code work. Like this:

class offerLow():
    @staticmethod
    def offer(self):
        return (thirdOfPrice * random.random())
    
    @staticmethod
    def idcode(self):
        self.idcode = 21

For more information about instance method, class method and static method: https://realpython.com/instance-class-and-static-methods-demystified/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sunflower