dimanche 1 mars 2015

using multiple if statements in function

Here is my code:



ac = a + c
bd = b + d

indices = random.sample(range(len(ac)),len(ac))
ac = list(map(ac.__getitem__, indices))
bd = list(map(bd.__getitem__, indices))


with open('DD{}.csv'.format(fileName), 'w') as f:
writer = csv.writer(f, delimiter=',')
writer.writerow(['trial','target location',' source target',' source distractor','target','rt'])

for i in range(len(ac)):

loc = [1, 2]
location = random.choice(loc)
if location == 1:
pos1 = [.05,.05]
pos2 = [-.05, -.05]
else:
pos1 = [-.05, -.05]
pos2 = [.05, .05]

distractorstim = visual.ImageStim(win=win, pos=pos1, size=[0.5,0.5])
distractorstim.autoDraw = True
targetstim = visual.ImageStim(win=win, pos=pos2, size=[0.5,0.5])
targetstim.autoDraw = True

targetstim.image = ac[i]
distractorstim.image = bd[i]
win.flip()
trialClock.reset()
core.wait(.05)
rt = trialClock.getTime()
for el in ac:
if el in a:
target = 'congruent'
else:
target = 'incongruent'



writer.writerow([i,location,ac[i],bd[i],target,rt])


So what this code does it it logs a bunch of information about a stimulus into an excel file. However, when I try to use the element function ('if el') to log data that is from list 'a', it will only log the last value repetitively. If I move the element function I can get it to log for each trial, but it will only log the last value for all everything else. Any idea how I might fix this? Any advice will be greatly appreciated. :)


Aucun commentaire:

Enregistrer un commentaire