#1 by otreesurvey
Hello, I want to assign one control group and 3 treatment groups in my survey. I used this code but when I run the demo with 4 participants all of them are assigned to the control group. Can someone help me? class Subsession(BaseSubsession): def creating_session(self): num_participants = len(self.get_players()) num_treatment_groups = 3 # Calculate the number of participants per treatment group participants_per_group = num_participants // (num_treatment_groups + 1) remaining_participants = num_participants % (num_treatment_groups + 1) # Assign participants to the control group control_group = self.get_players()[:participants_per_group] # Assign remaining participants to the treatment groups treatment_groups = [self.get_players()[i:i + participants_per_group] for i in range(participants_per_group, num_participants, participants_per_group)] # Set group matrix self.set_group_matrix([control_group] + treatment_groups) # Print for debugging print("Control Group:") for player in control_group: print(f"Participant {player.participant.label} treatment group: {player.treatment_group}") print("Treatment Groups:") for i, group in enumerate(self.get_groups()): for player in group.get_players(): print(f"Participant {player.participant.label} treatment group: {player.treatment_group}")