Help with storing 3 correct answers and then force end trial


I am trying to write a simple code where 3 answers are recorded out of 6 possible answers. The 3 answers inputted should be checked to either be correct or incorrect (return 1 for correct and 0 for incorrect). Upon 3 answers being submitted, the routine should be forced to end.

I have attached my current code and the keyboard component. I am unsure as how to stop the routine from immediately ending when only 1 possible answer is submitted.

Thank you in advance for any help.

Remove the tick from “Force end of routine”

Each Frame

if answt7.keys:
     if len(answt.keys) == 3:
          continueRoutine = False

End Routine

if "2" in answt7.keys and "4" in answt7.keys and "5" in answt.keys:

Thank you for your help. I had some errors in the “each frame” section, but I edited the code to this and it now works.

I am still having issues with the section for “end routine”. I have 6 options total possible (1,2,3,4,5,6) and 3 out of the 6 are correct. In this case the three correct are 2,4,5. I want to write some code that will check and return the amount of correct responses. So if out of 3 responses, only 1 is correct, “1” is returned. If 2 responses out of 3 are correct, “2” is returned, and if all 3 responses are correct, “3” is returned. The code on lines 17-18 works well when all 3 responses selected are correct, but I am having trouble writing some simple code for when only 1, or when only 2 out of the 3 responses are correct. Is there a simpler way of writing this code without having to write out each possible permutation?

Thanks in advance



Could you do a counter? So for example:

corrCount = 0
if "2" in answt7.keys:
     corrCount +=1
if "4" in answt7.keys:
    corrCount +=1
if "5" in answt7.keys:
    corrCount +=1

Thank you, this is exactly what I was looking for.