from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, Currency as c, currency_range, ) import random author = 'Chanjoo Lee' doc = """ Dice Task """ class Constants(BaseConstants): name_in_url = 'dice_task' players_per_group = None num_rounds = 6 earning_match=100 earning_not=20 chosen_round=random.randrange(1, 7) class Subsession(BaseSubsession): def creating_session(self): players = self.get_players() for player in players: player.dice=random.randint(1,6) class Group(BaseGroup): pass class Player(BasePlayer): choice = models.IntegerField(widget=widgets.RadioSelectHorizontal, choices=[[0,"2 or lower"],[1, "3 or higher"]], label="" ) dice=models.IntegerField() earning=models.IntegerField() def result_calculater(self): if self.choice==0 and self.dice <= 2: self.earning=Constants.earning_match elif self.choice and self.dice > 2: self.earning = Constants.earning_match else: self.earning=Constants.earning_not