OS : Win10 PsychoPy version :2020.2.5 Standard Standalone? Yes What are you trying to achieve?:
To end a loop based on the percentage of correct responses after some trials.
It’s my first time with psychopy and I know if i use this code the routine stops after 3 correct responses:
score+=key_resp_2.corr
thisExp.addData(‘Score’,score)
if score >= 3:
trial.finished = True
But I don’t know how to code to end the loop with 95% correct responses of at least 25 trials.
The code you have adds 1 to score if a correct response is given, to continuously work out an average I would recommend instead appending1 to score. So rather than:
score = 0
score += key_resp_2.corr
you would do
score = []
score.append(key_resp_2.corr)
what this means is that score becomes a list of 1s and 0s, which you can then work out an average for and compare this average to 0.95 (which it will be if it’s 95% correct):
if average(score) >= 0.95:
trial.finished = True
A word of caution: You might want to start off with a few 0s in score rather than have it blank, otherwise they will get one correct answer and the task will finish because their correct % will be 100%. Either that or don’t calculate average until a few repetitions in.
Also, I solved the problem of the posible and unexpected finish of the experiment with just one correct answer adding a minimun of correct answers required. Before experiment:
score =
scorr = 0
End Routine:
score.append(key_resp_2.corr)
scorr+=key_resp_2.corr
thisExp.addData(‘Score’,score)
if (average(score) >= 0.95 and scorr >= 10):
trial.finished = True