import random from otree.api import * doc = """ Treatment1 """ class C(BaseConstants): NAME_IN_URL = 'treatment1_CM' PLAYERS_PER_GROUP = None TASKS = ['inflation', 'income', 'Bayesian', 'quantity', 'unemployment'] NUM_ROUNDS = len(TASKS) CM100 = __name__ + '/CM100.html' BONUS = 3 economics = [ dict(name='Inflation', label="U.S. inflation rate"), dict(name='Unemployment', label="U.S. unemployment rate"), dict(name='Income', label="Income of 30-year-old and full time workers"), dict(name='Edu', label="Educational attainment"), dict(name='No', label="None of above"), ] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # record the submission for each task num_failed_attempts = models.IntegerField(initial=0) failed_more_than1 = models.BooleanField(initial=False) CC_Q1 = models.IntegerField( label='', choices=[ [1, 'There are 5 tasks in total, and my submitted guess in every one of them will get paid. Thus, I can strategize across tasks to hedge.'], [2, 'There are 5 tasks in total. The computer will randomly select one of them, and my bonus will depend on my submitted guess to this one task. Thus, there is no point for me in strategizing across tasks.'], ], widget=widgets.RadioSelect ) CC_Q2 = models.IntegerField( label='', choices=[ [1, 'Randomly select a number to submit'], [2, 'Always submit 0'], [3, 'Always submit the number in the middle of the slider bar'], [4, 'Always submit the maximum number of the slider bar'], [5, 'Submit the best guess he can make, i.e., 20%.'], ], widget=widgets.RadioSelect ) CC_Q3 = models.IntegerField() # Familiar with statistics statistics = models.IntegerField( label='', choices=[ [1, 'Yes'], [2, 'No'] ], widget=widgets.RadioSelect ) # Familiar with economic variables Inflation = models.BooleanField(blank=True) Unemployment = models.BooleanField(blank=True) Income = models.BooleanField(blank=True) Edu = models.BooleanField(blank=True) No = models.BooleanField(blank=True) # economics = models.IntegerField( # label='', # choices=[ # [1, 'Inflation rates'], # [2, 'Unemployment rates'], # [3, 'Income of 30-year-old and full-time workers'], # [4, 'Educational attainments across states'], # [5, 'None of above'] # ], # widget=CheckboxSelectMultiple(attrs={'class': 'checkbox'}) # ) feedbackIR = models.LongStringField( blank=True, label='' ) feedbackBB = models.LongStringField( blank=True, label='' ) complexity = models.LongStringField( blank=True, label='' ) comments = models.LongStringField( blank=True, label='' ) CM_Task1 = models.IntegerField() CM_Task2 = models.IntegerField() CM_Task3 = models.IntegerField() CM_Task4 = models.IntegerField() CM_Task5 = models.IntegerField() # record the order for each task Task1_order = models.IntegerField() Task2_order = models.IntegerField() Task3_order = models.IntegerField() Task4_order = models.IntegerField() Task5_order = models.IntegerField() # record the parameter for each task inflation_index = models.IntegerField() income_index = models.IntegerField() Bayesian_index = models.IntegerField() quantity_index = models.IntegerField() unemployment_index = models.IntegerField() # record the correct answer for each task Task1_answer = models.IntegerField() Task2_answer = models.IntegerField() Task3_answer = models.IntegerField() Task4_answer = models.IntegerField() Task5_answer = models.IntegerField() # 1 for inflation rate # 2 for income # 3 for Bayesian # 4 for quantity # 5 for unemployment # FUNCTIONS # creating session gets executed for each round independently def creating_session(subsession: Subsession): # set the payoff round if subsession.round_number == 1: subsession.session.payoff_round = random.randint(1, 5) # Return a number between 1 and 5 as a payoff round print('payoff_round (in treatment1 round 1):', subsession.session.payoff_round) # randomize the order of tasks for each participant for p in subsession.get_players(): round_numbers = list(range(1, C.NUM_ROUNDS+1)) random.shuffle(round_numbers) print('task_order for treatment1:', round_numbers) task_rounds = dict(zip(C.TASKS, round_numbers)) p.participant.task_rounds_treatment1 = task_rounds print('inflation order:', p.participant.task_rounds_treatment1['inflation']) print('income order:', p.participant.task_rounds_treatment1['income']) print('Bayesian order:', p.participant.task_rounds_treatment1['Bayesian']) print('quantity order:', p.participant.task_rounds_treatment1['quantity']) print('unemployment order:', p.participant.task_rounds_treatment1['unemployment']) # PAGES class Intro1(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['inflation'] @staticmethod def before_next_page(player, timeout_happened): player.inflation_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Inflation parameter:", player.inflation_index) print("round number:", player.round_number) print("task_rounds_treatment1[inflation]:", player.participant.task_rounds_treatment1['inflation']) class Inflation1(Page): form_model = 'player' form_fields = ['CM_Task1'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['inflation'] and player.inflation_index == 1 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task1 print("Task1 result:", result) # the Bayesian answer Bayesian = 56 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task1 num0:", num0) if num0 > Bayesian: truth = 1 # if above the Bayesian print("Task1 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task1 num1:", num1) print("Task1 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task1 payoff:", player.payoff) # save the parameters player.Task1_answer = 56 player.Task1_order = player.round_number class Inflation2(Page): form_model = 'player' form_fields = ['CM_Task1'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['inflation'] and player.inflation_index == 2 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task1 print("Task1 result:", result) # the Bayesian answer Bayesian = 77 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task1 num0:", num0) if num0 > Bayesian: truth = 1 print("Task1 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task1 num1:", num1) print("Task1 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task1 payoff:", player.payoff) # save the parameters player.Task1_answer = 77 player.Task1_order = player.round_number class Inflation3(Page): form_model = 'player' form_fields = ['CM_Task1'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['inflation'] and player.inflation_index == 3 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task1 print("Task1 result:", result) # the Bayesian answer Bayesian = 92 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task1 num0:", num0) if num0 > Bayesian: truth = 1 print("Task1 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task1 num1:", num1) print("Task1 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task1 payoff:", player.payoff) # save the parameters player.Task1_answer = 92 player.Task1_order = player.round_number class Intro2(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['income'] @staticmethod def before_next_page(player, timeout_happened): player.income_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Income parameter:", player.income_index) print("round number:", player.round_number) print("task_rounds_treatment1[income]:", player.participant.task_rounds_treatment1['income']) class Income1(Page): form_model = 'player' form_fields = ['CM_Task2'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['income'] and player.income_index == 1 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task2 print("Task2 result:", result) # the Bayesian answer Bayesian = 7 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task2 num0:", num0) if num0 > Bayesian: truth = 1 print("Task2 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task2 num1:", num1) print("Task2 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task2 payoff", player.payoff) # save parameters player.Task2_answer = 7 player.Task2_order = player.round_number class Income2(Page): form_model = 'player' form_fields = ['CM_Task2'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['income'] and player.income_index == 2 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task2 print("Task2 result:", result) # the Bayesian answer Bayesian = 30 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task2 num0:", num0) if num0 > Bayesian: truth = 1 print("Task2 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task2 num1:", num1) print("Task2 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task2 payoff", player.payoff) # save parameters player.Task2_answer = 30 player.Task2_order = player.round_number class Income3(Page): form_model = 'player' form_fields = ['CM_Task2'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['income'] and player.income_index == 3 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task2 print("Task2 result:", result) # the Bayesian answer Bayesian = 45 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task2 num0:", num0) if num0 > Bayesian: truth = 1 print("Task2 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task2 num1:", num1) print("Task2 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task2 payoff", player.payoff) # save parameters player.Task2_answer = 45 player.Task2_order = player.round_number class Intro3(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['Bayesian'] @staticmethod def before_next_page(player, timeout_happened): player.Bayesian_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Bayesian parameter:", player.Bayesian_index) print("round number:", player.round_number) print("task_rounds_treatment1[Bayesian]:", player.participant.task_rounds_treatment1['Bayesian']) class Bayesian1(Page): form_model = 'player' form_fields = ['CM_Task3'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['Bayesian'] and player.Bayesian_index == 1 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task3 print("Task3 result:", result) # the Bayesian answer Bayesian = 6 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task3 num0:", num0) if num0 > Bayesian: truth = 1 print("Task3 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task3 num1:", num1) print("Task3 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task3 payoff:", player.payoff) # save parameters player.Task3_answer = 6 player.Task3_order = player.round_number class Bayesian2(Page): form_model = 'player' form_fields = ['CM_Task3'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['Bayesian'] and player.Bayesian_index == 2 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task3 print("Task3 result:", result) # the Bayesian answer Bayesian = 47 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task3 num0:", num0) if num0 > Bayesian: truth = 1 print("Task3 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task3 num1:", num1) print("Task3 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task3 payoff:", player.payoff) # save parameters player.Task3_answer = 47 player.Task3_order = player.round_number class Bayesian3(Page): form_model = 'player' form_fields = ['CM_Task3'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['Bayesian'] and player.Bayesian_index == 3 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task3 print("Task3 result:", result) # the Bayesian answer Bayesian = 33 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task3 num0:", num0) if num0 > Bayesian: truth = 1 print("Task3 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task3 num1:", num1) print("Task3 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task3 payoff:", player.payoff) # save parameters player.Task3_answer = 33 player.Task3_order = player.round_number class Intro4(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['quantity'] @staticmethod def before_next_page(player, timeout_happened): player.quantity_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Quantity parameter:", player.quantity_index) print("round number:", player.round_number) print("task_rounds_treatment1[quantity]:", player.participant.task_rounds_treatment1['quantity']) class Quantity1(Page): form_model = 'player' form_fields = ['CM_Task4'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['quantity'] and player.quantity_index == 1 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task4 print("Task4 result:", result) # the Bayesian answer Bayesian = 3 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task4 num0:", num0) if num0 > Bayesian: truth = 1 print("Task4 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task4 num1:", num1) print("Task4 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task4 payoff:", player.payoff) # save parameters player.Task4_answer = 3 player.Task4_order = player.round_number class Quantity2(Page): form_model = 'player' form_fields = ['CM_Task4'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['quantity'] and player.quantity_index == 2 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task4 print("Task4 result:", result) # the Bayesian answer Bayesian = 12 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task4 num0:", num0) if num0 > Bayesian: truth = 1 print("Task4 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task4 num1:", num1) print("Task4 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task4 payoff:", player.payoff) # save parameters player.Task4_answer = 12 player.Task4_order = player.round_number class Quantity3(Page): form_model = 'player' form_fields = ['CM_Task4'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['quantity'] and player.quantity_index == 3 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task4 print("Task4 result:", result) # the Bayesian answer Bayesian = 49 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task4 num0:", num0) if num0 > Bayesian: truth = 1 print("Task4 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task4 num1:", num1) print("Task4 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task4 payoff:", player.payoff) # save parameters player.Task4_answer = 49 player.Task4_order = player.round_number class Intro5(Page): @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['unemployment'] @staticmethod def before_next_page(player, timeout_happened): player.unemployment_index = random.randint(1, 3) # random draw a number between 1 and 3 to determine the parameter print("Unemployment parameter:", player.unemployment_index) print("round number:", player.round_number) print("task_rounds_treatment1[unemployment]:", player.participant.task_rounds_treatment1['unemployment']) class Unemployment1(Page): form_model = 'player' form_fields = ['CM_Task5'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['unemployment'] and player.unemployment_index == 1 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task5 print("Task5 result:", result) # the Bayesian answer Bayesian = 56 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task5 num0:", num0) if num0 > Bayesian: truth = 1 print("Task5 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task5 num1:", num1) print("Task5 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task5 payoff:", player.payoff) # save parameters player.Task5_answer = 56 player.Task5_order = player.round_number class Unemployment2(Page): form_model = 'player' form_fields = ['CM_Task5'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['unemployment'] and player.unemployment_index == 2 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task5 print("Task5 result:", result) # the Bayesian answer Bayesian = 84 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task5 num0:", num0) if num0 > Bayesian: truth = 1 print("Task5 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task5 num1:", num1) print("Task5 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task5 payoff:", player.payoff) # save parameters player.Task5_answer = 84 player.Task5_order = player.round_number class Unemployment3(Page): form_model = 'player' form_fields = ['CM_Task5'] @staticmethod def is_displayed(player: Player): return player.round_number == player.participant.task_rounds_treatment1['unemployment'] and player.unemployment_index == 3 @staticmethod def before_next_page(player, timeout_happened): if player.session.payoff_round == player.round_number: # determine the result for payoff calculation result = player.CM_Task5 print("Task5 result:", result) # the Bayesian answer Bayesian = 98 # the truth is either above the Bayesian or below the Bayesian truth = 0 # if below and equal to the Bayesian # determine the truth num0 = random.randint(1, 100) print("Task5 num0:", num0) if num0 > Bayesian: truth = 1 print("Task5 truth:", truth) # determine the payoff based on the truth num1 = random.randint(0, 100) num2 = random.randint(0, 100) print("Task5 num1:", num1) print("Task5 num2:", num2) if truth == 0: if result > num1 or result > num2: player.payoff = C.BONUS else: player.payoff = 0 if truth == 1: if result < num1 or result < num2: player.payoff = C.BONUS else: player.payoff = 0 print("Task5 payoff:", player.payoff) # save parameters player.Task5_answer = 98 player.Task5_order = player.round_number class InstructionCM(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 1 class ComprehensionCheckCM(Page): form_model = 'player' form_fields = ['CC_Q1', 'CC_Q2'] @staticmethod def is_displayed(player: Player): return player.round_number == 1 @staticmethod def error_message(player: Player, values): # define error messages for each question error_messages = dict( CC_Q1='Incorrect answer! Hint: Because we only pay you based on a single guess of yours, there is no point for you to strategize across tasks.', CC_Q2='Incorrect answer! Hint: We designed the bonus rule to make sure that you can secure the largest chance of winning the prize by reporting your best guess. Therefore, in each task, to maximize your chance of receiving the bonus, you should simply always submit your best guess.', #CC_Q3='Incorrect answer! Hint: 1/2*1/2 = 1/4 = 25%', ) # define the correct solutions for each question solutions = dict( CC_Q1=2, CC_Q2=5, #CC_Q3=25, ) # initialize an empty dictionary for errors errors = dict() # check each question and add an error message if the answer is incorrect for field_name in solutions: if values[field_name] != solutions[field_name]: errors[field_name] = error_messages[field_name] player.num_failed_attempts += 1 if errors: if player.num_failed_attempts >= 1: player.failed_more_than1 = True else: return errors @staticmethod def before_next_page(player: Player, timeout_happened): session = player.session participant = player.participant if player.failed_more_than1 == False: session.completions_by_treatment[participant.color] += 1 else: session.completions_by_treatment[participant.color] += 0 class survey(Page): form_model = 'player' form_fields = ['statistics', 'feedbackIR', 'feedbackBB', 'complexity', 'comments', 'Inflation', 'Unemployment', 'Income', 'Edu', 'No'] @staticmethod def is_displayed(player: Player): return player.round_number == 5 class End(Page): @staticmethod def is_displayed(player: Player): return player.round_number == 5 @staticmethod def before_next_page(player, timeout_happened): player.participant.finished = True class Failed(Page): @staticmethod def is_displayed(player: Player): return player.failed_more_than1 page_sequence = [InstructionCM, ComprehensionCheckCM, Failed, Intro1, Inflation1, Inflation2, Inflation3, Intro2, Income1, Income2, Income3, Intro3, Bayesian1, Bayesian2, Bayesian3, Intro4, Quantity1, Quantity2, Quantity3, Intro5, Unemployment1, Unemployment2, Unemployment3, survey, End ]