#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

# partial randomization of a loop

Hello

I need to design an experiment with 5 color-word Stroop trials in a row (1 congruent, 4 incongruent in a random order), followed by a forced choice math question (say a or b).

A block is 20 repeats of this process, with 10 math questions with response 'a' and 10 with response 'b' that should also be in a random order.

is there a way to do it in the GUI?

if not, a link to the relevant information about how to code it would be appreciated.

Thank you!

Tali.

• Hi Tali,

if the math questions and the stroop trials should be randomized independently from each other, you can't do this in the GUI, but have to program it directly. It isn't that complicated though. Something simple like this will do:

```import random

word_list = ['red', 'green', 'blue']

cong_color_dict = {'red':(255, 0 ,0),
'green':(0, 255, 0),
'blue':(0, 0, 255)}

incong_color_dict = {'red':[(0, 255, 0), (0, 0 ,255)],
'green':[(255, 0, 0), (0, 0 ,255)],
'blue':[(0, 255, 0), (255, 0 ,0)]}

# make math questions (no idea what you have in mind)
questions_temp = 20 * ["2 + 10"]
answer_array = 10 * ['a', 'b']
random.shuffle(questions_dict)

# containers for the info
all_trials = dict(stroop_words=[], stroop_colors=[], questions=[],
options_a=[], options_b=[], question_correct_resp=[])

for rep in range(20):
words = []
for trial in range(5):
word = random.choice(word_list)
# every 5th one is congruent the other four are incongruent
if trial == 0:
words.append((word, cong_color_dict[word]))
else:
words.append((word, random.choice(incong_color_dict[word])))

# randomize the order of the five trials
random.shuffle(words)
all_trials['stroop_words'] += [word[0] for word in words]
all_trials['stroop_colors'] += [word[1] for word in words]

all_trials['questions'].append(questions_dict[rep]['question'])
```

Now you can have a loop over 120 trials and in the in trial sequence pop the items you need from the prepared list

Hope this helps a bit,

Eduard

• edited May 2023

Thank you Eduard!

Is it possible to use pictures instead of text for the stimuli?

The Stroop words are in Hebrew and the math problems requires pictures.

I'm just not sure how to connect the file pool to the script.

If there is a manual that explain it, it would also help

Thanks again! it really helps!

Tali

• Lucky you, there is a manual that explains it: https://osdoc.cogsci.nl/3.3/manual/python/pool/

Whether text or images, it's all the same for this problem here.

Hope this helps,

Eduard

• Thank you! I actually found a way to do it using only GUI using several levels of nested loops.

It's messy and not as elegant, but when it comes to coding, I'm really challenged 😑.