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 = 'own_money_lottery' players_per_group = None num_rounds = 1 right_pay = c(160) wrong_pay = c(100) high_lottery = c(300) low_lottery = c(50) 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.high_lottery if self.lottery and not self.lottery_outcome: self.payoff = Constants.low_lottery if not self.lottery: self.payoff = Constants.right_pay else: if self.lottery and self.lottery_outcome: self.payoff = Constants.high_lottery if self.lottery and not self.lottery_outcome: self.payoff = Constants.low_lottery if not self.lottery: self.payoff = Constants.wrong_pay