from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Your name here' doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'exercise2' players_per_group = None num_rounds = 1 A_l_pay=c(300) A_u_pay=c(50) B_r_pay=c(160) B_w_pay=c(100) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): calculation = models.IntegerField(label="What is the solution for 56+147") lottery = models.BooleanField( choices=[[True, 'Yes'], [False, 'No']], label="Do you want to enter the lottery?", widget=widgets.RadioSelect) lottery_outcome = models.BooleanField() def set_payoff(self): self.lottery_outcome = random.choice([True, False]) if self.calculation == 203: if self.lottery and self.lottery_outcome: self.payoff = Constants.A_l_pay if self.lottery and not self.lottery_outcome: self.payoff = Constants.A_u_pay if not self.lottery: self.payoff = Constants.B_r_pay else: if self.lottery and self.lottery_outcome: self.payoff = Constants.A_l_pay if self.lottery and not self.lottery_outcome: self.payoff = Constants.A_u_pay if not self.lottery: self.payoff = Constants.B_w_pay