from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '' class Constants(BaseConstants): name_in_url = 'Redistribution' players_per_group = None num_rounds = 1 endowment = c(100) class Subsession(BaseSubsession): pass class Group(BaseGroup): Tax = models.FloatField() def set_payoff1(self): players=self.get_players() import random tax_list=[p.Taxation for p in players] tax=float(random.choice(tax_list)/100) for p in players: p.payoff=Constants.endowment if p.Q1==False: p.payoff+=10 if p.Q2==False: p.payoff+=10 if p.Q3==1560: p.payoff+=10 if p.Q4==False: p.payoff+=10 if p.Q5==6561: p.payoff+=10 payoffs=[p.payoff for p in players] totaloutcome=sum(payoffs) totalcontribution=float(totaloutcome*tax) individual_share=float(totalcontribution/len(players)) for p in players: p.payoff=float((1-tax)*p.payoff+individual_share) self.Tax=tax class Player(BasePlayer): Q1 = models.BooleanField(choices=[[True, 'Sì'], [False, 'No']], label='La capitale della Slovenia è Maribor') Q2 = models.BooleanField(choices=[[True, 'Sì'], [False, 'No']], label='La Francia è una repubblica di tipo presidenziale') Q3 = models.IntegerField(choices=[[1560, '1560'], [1500, '1500'], [1240, '1240'], [1120, '1120'], [1100, '1100']], label='Qual è la somma dei numeri dispari tra 35 e 85, inclusi?') Q4 = models.BooleanField(choices=[[True, 'Sì'], [False, 'No']], label="Il fiume più lungo d'Europa è la Senna") Q5 = models.IntegerField(choices=[[6503, '6503'], [6561, '6561'], [6769, '6769'], [6877, '6877'], [7009, '7009']], label='3^8=') Taxation = models.FloatField(choices=[[10, '10'], [20, '20'], [30, '30'], [40, '40'], [50, '50'], [60, '60'], [70, '70'], [80, '80'], [90, '90']], label='Scegli il livello di tassazione (%):')