End experiment based on the % of correct answers

If this template helps then use it. If not then just delete and start from scratch.
PsychoPy version 3-3.1.5 (Builder)
(Sorry for my english, i am French)

Hi, in my experiment, a participant has to complete a mental fatigue task, its an alternation of numbers and letters. They have to press “2” when the number is even, “3” when he is odd, and “space” if 2 identical letters follow each other.
I want to make it end when participants get at least 85% of the trials in the last block correct before they can finish.
If the participant gets less than 85% the task continue.

Also, the letters and numbers should continue to scroll even if the participants does not respond. Finally, the STD (stimulus time duration) of letters and numbers must adapt to the participant respond time.

I try this :
Began routine

ACQkeyRespcorrs = []
minNrPractice = 36  # min number of trials to practice
considerNrTrials = 12  # number of trials to consider for accuracy calculation
minAccuracy = 0.9

End Routine

respcorrs.append(resp.corr)  # assumes your keyboard component is called "ACQkeyResp"

if len(respcorrs) >= minNrPractice:

    respcorrsRecent = respcorrs[-considerNrTrials:]
    
    respcorrsSum = sum(respcorrsRecent)  # only works if error=0 and correct=1
    
    accuracy = float(respcorrsSum)/considerNrTrials
    
    if accuracy >= minAccuracy:
        break

I found this on the forum, but i don’t know if its the good solution, i am a beginner in Psychopy

Thank you

Replace break with something like:

name_of_your_loop.finished = True

Also bear in mind that 10/12 = 83.3% and 11/12 = 91.7%, so to pass your test with only 12 trials counted, people need more than your criterion value of 85 or 90%.

Thank you for your help, it works !
And do you know how to respond to this questions: “the letters and numbers should continue to scroll even if the participants does not respond. Finally, the STD (stimulus time duration) of letters and numbers must adapt to the participant respond time”.
Have a nice day

Just set all of your components to have a fixed duration, so that the routine will end even if a response has not been made by that time.

Sorry, you’ll need to explain this to me in more detail.

Thank you for your help

The appearance of letters and numbers depends on the response time of the participant. So if the participant presses correctly and quickly, the letters and numbers will appear faster. And if the participant presses correctly but slowly, the numbers and letters will appear less quickly. So the duration of the stimulus depend of the participant respond time.

OK, that explains the general concept. But to get a computer to do anything requires breaking it down into a set of very precise steps - we need to understand those steps so we can describe how to implement them.That needs both detail and precision in terminology e.g. in the description above you seem to interchangeably refer to how quickly a stimulus appears (which I take to mean its time of onset) with what the duration of the stimulus is.

So to give you useful guidance, we need a careful description. Think the level of detail that would appear in the methods section of a paper - what a reader would need to know to understand your task is what we need to describe how to translate it into a PsychoPy implementation.

I will try to be more precise:

The time of appearance of a stimulus is basically 1.5 seconds, so it remains on the screen for 1.5 seconds. During the task, the participant will respond more or less quickly to the appearance of the stimuli by pressing the response key on the keyboard.
I have therefore put in my external list an appearance time of 1.5 seconds for each stimulus. However, this appearance time should be adapted to the participant’s response time, and that’s what I don’t know how to do.
So for example, if the participant responds very quickly, the appearance time of the stimuli will automatically decrease.