from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, Page, WaitPage ) doc = '' class Constants(BaseConstants): name_in_url = 'my_public_goods' players_per_group = 3 num_rounds = 1 endowment = c(100) multiplier = 2 class Subsession(BaseSubsession): pass def set_payoffs(group): players = group.get_players() contributions = [p.contribution for p in players] group.total_contribution = sum(contributions) group.individual_share = group.total_contribution*Constants.multiplier/Constants.players_per_group for p in players: p.payoff = Constants.endowment-p.contribution+group.individual_share payoffs = [p.payoff for p in players] print('payoffs are:', payoffs) group.total_payoff = sum(payoffs) class Group(BaseGroup): total_contribution = models.CurrencyField() individual_share = models.CurrencyField() total_payoff = models.CurrencyField() set_payoffs = set_payoffs class Player(BasePlayer): contribution = models.CurrencyField(label='How much do you want to contribute?', max=Constants.endowment, min=0)