psychopy.org | Reference | Downloads | Github

Giving feedback based on the number of trials inside the loop

Hello!
I have the following problem.I am trying to give participant a feedback on the speed of his response, using his performance on past trials as a criterion. Specifically, I have 70 trials. Until trial #25, the criterion is his median performance in past trials. After trial #25, it is 70th percentile of his performance. To achieve that, in the feedback routine I use the following code at the start of each routine:

if trials.thisN < 24:
       a =trials.data['key_resp_2.rt']
       rtcutoff = np.median(a)
       if key_resp_2.rt >= rtcutoff:
                msg = 'Too slow'
       else:
                msg = 'good job!'
else:
        a = trials.data['key_resp_2.rt']
        rtcutoff = np.percentile (a, 70)
         if key_resp_2.rt >= rtcutoff:
                msg = 'Too slow'
       else:
                msg = 'good job!'

However, I have a problem with this. For some reason, until trial 24 (the 25th trial) rtcutoff is always zero. I have tried to fix it, but the most I have accomplished was making the cutoff the same as the most recent RT (hence, good job never pops up - but only until trial 24). Thank you in advance!