Counterbalancing with list

Hello! I am making a posner task, and want to have it so it counterbalances the order of exogenous, endogenous, and both types of cues.

I initially had the choice between the three chosen at the start with randint either 1,2,3
if number == 1:
row_variable = ‘1:16’
elif number == 2:
row_variable = ‘17:30’
elif number == 3:
row_variable = ‘1:30’

I was hoping to use lists to counterbalance the order of this with three repetitions. I added a second loop called trials2 and added this to begin experiment:
balance = randint(1,6)
counterbalance1 = [“1”,“2”,“3”]
counterbalance2 = [“1”,“3”,“2”]
counterbalance3 = [“2”,“1”,“3”]
counterbalance4 = [“2”,“3”,“1”]
counterbalance5 = [“3”,“1”,“2”]
counterbalance6 = [“3”,“2”,“1”]

if trials2.thisN == 0:
number == ‘counterbalance’+int(balance[1])
elif trials2.thisN == 1:
number == ‘counterbalance’+int(balance[2])
elif trials2.thisN == 2:
number == ‘counterbalance’+int(balance[3])
else:
number == 3
if number == 1:
row_variable = ‘1:16’
elif number == 2:
row_variable = ‘17:30’
elif number == 3:
row_variable = ‘1:30’

It was originally saying that “trials_2” is not defined, so I moved the second section to begin routine (thinking it wasn’t working since the routine hadn’t started yet) and now I get this error:

TypeError: int() argument must be a string, a bytes-like object or a number, not ‘NoneType’

I have uploaded the files, any suggestions would be great!

Thanks

posner_mix.xlsx (9.6 KB)
posner_mix_testing.psyexp (25.6 KB)

Hello,

I would say, that the errors

shows that your are adding an int to list of strings.

Best wishes Jens

Hello Jens!

Thank you for the note, what would I have to change in the code to make it work?

Hello Dino,

well, I don’t know what you try to achieve but if you want to add a constant to each element of a list you can use the following code:

a = [1,2,3]
aplus = [i+3 for i in a]
  • the list elements of a are numbers: 1,2,3 and not strings as in your case [“1”,“2”,“3”]
  • you need a loop to add something to each list-element

Best wishes Jens