from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range ) doc = '' class Constants(BaseConstants): name_in_url = 'Redistribution2' players_per_group = None num_rounds = 1 endowment = c(100) class Subsession(BaseSubsession): pass class Group(BaseGroup): Tax = models.FloatField() HighPayoff = models.IntegerField() LowPayoff = models.IntegerField() Payoff1 = models.IntegerField() Payoff2 = models.IntegerField() Payoff3 = models.IntegerField() Payoff4 = models.IntegerField() Payoff5 = models.IntegerField() def set_payoff(self): players=self.get_players() import random tax_list=[p.Taxation for p in players] tax=float(random.choice(tax_list)/100) self.HighPayoff=10 self.LowPayoff=0 payoff_random=[self.HighPayoff, self.LowPayoff] for p in players: p.payoff=Constants.endowment if p.Q1==False: self.Payoff1=random.choice(payoff_random) p.payoff+=self.Payoff1 if p.Q2==False: self.Payoff2=random.choice(payoff_random) p.payoff+=self.Payoff2 if p.Q3==12: self.Payoff3=random.choice(payoff_random) p.payoff+=self.Payoff3 if p.Q4==True: self.Payoff4=random.choice(payoff_random) p.payoff+=self.Payoff4 if p.Q5==3: self.Payoff5=random.choice(payoff_random) p.payoff+=self.Payoff5 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, 'Yes'], [False, 'No']], label='La capitale della Macedonia è Bitola') Q2 = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label="Il Presidente del Consiglio dei Ministri durante l'ingresso dell'Italia nella I Guerra Mondiale fu Giolitti") Q4 = models.BooleanField(choices=[[True, 'Yes'], [False, 'No']], label="La Finlandia ha l'Euro come valuta") Q5 = models.FloatField(choices=[[2, '2'], [2.5, '2.5'], [3, '3'], [3.5, '3.5'], [4, '4']], label='Se la media aritmetica di "3,k,2,8,m,3" è 4, e "k" e "m" sono due numeri interi tali diversi tra loro, qual è la mediana?') Taxation = models.IntegerField(choices=[[10, '10'], [20, '20'], [30, '30'], [40, '40'], [50, '50'], [60, '60'], [70, '70'], [80, '80'], [90, '90']], label='Quale livello di tassazione vuoi scegliere (%)?') Q3 = models.IntegerField(choices=[[6, '6'], [12, '12'], [24, '24'], [36, '36'], [48, '48']], label='Se n è un numero intero positivo e n^2 è divisibile per 72, allora il numero intero positivo più grande che divide n è:')