| Reference | Downloads | Github

Create lists of four digits for each participant

Hi all,

I´m totally new to both - PsychoPy and Python - and any help would be appreciated. I´d like to program an experiment in which participants learn two lists, each containing four digits. The digits on the second and the fourth position in each list are the same (e.g. list 1 = 3 5 7 9; list 2 = 2 5 1 9). Is there any way to randomly create both lists for each participant and to refer to these digits from the excel-file, e.g. by labelling them digit1; digit2 and so forth…? By this I could define the correct answers in the excel file, but I would not have to predefine the lists in the excel-file.
I hope I explained my problem understandable. Please let me know if anything is unclear. Thanks a lot in advance for advices and coding-inspiration :slightly_smiling_face:


Hi @Frida, this is easily done with Builder, and using a code component. To be of better assistance, perhaps you could provide more information about your task - think methods section… Also, how do you determine which list is the correct answer?

Thanks a lot for your reply. Well the task is inspired by a typical Sternberg Task. Participants have to learn the two lists at the beginning of the experiment. During the test phase, they are shown one digit on each trial. They have to verify (just a “yes” or “no” decision), whether this digit belongs to one of the two lists they learned in the beginning of the experiment. So my - rather naive - idea was to randomly draw the value for each digit (digit1, digit2, digit3…digit 8) in the two lists from an array of 0-9 (by using a code component) and to refer to these digits from the excelfile by just labelling them digit1, digit2… If this would work, I could also define easily the correctness of the answer via the excelfile. I hope I could make it clearer now. Thanks a lot!

Hi again!
I´m a few steps further now with my code component and maybe I can explain my issue more precisely and understandable.
I created the following code component:

import random
digits = [1,2,3,4,5,6,7,8,9]

digit_1 = digits[0]
digit_2 = digits[1]
digit_3 = digits[2]
digit_4 = digits[3]

digit_5 = digits[4]
digit_6 = digits[1]
digit_7 = digits[5]
digit_8 = digits[3]

digit_9 = digits[6]
digit_10 = digits[7]

My conditions file looks as follows:

Is there any possibility, to define in the code component, that digit_1, digit_2,…in the conditions file get the values generated via the code component? That would be absolutely great :slight_smile:
Thanks a lot in advance! I hope it got clearer now.

Hi @FridaWoods, good job. I think you can achieve what you want to do using the Python eval function. So in place of $target for your text stim, use $eval(target).

Hi again,
thank you so much! That works perfectly. I really appreciate your help. One last question concerning this topic arose: in the beginning of the experiment the participants are presented the two lists containing the digits. Its eight polygons each containing one of the digits. Is it possible to refer from the text stimulus directly to a specific element of the target-condition in my conditions file?So I naively thought of something like $eval(target$digit_1)…which of course didn´t work :wink: I also tried to define it directly in the code:

digit1 = visual.TextStim(win=win, name='digit1',
    pos=[0,0], height=0.08, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 
digit2 = visual.TextStim(win=win, name='digit2',
    pos=[0,0], height=0.08, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1, 

…but this also didn´t work…Do you have an idea how I can solve this? Thanks!

Hi Frida,
you might want to try this:
digit_1_num = digits[0] # you have name conflict

digit1 = visual.TextStim(win=win, name=‘digit1’,
text=str(digit_1_num), … #here you might have problem when using an integer as a string input…

Hope it helps…
Let know if you need further help.

Hi Natalia,
thanks a lot for your help! Yes it works :slight_smile: