Repeating unsolved tasks after break

I’m doing an experiment in PsychoPy. I will have two stages of solving problems, between which there is a break. I need to have tasks in the second cycle that the subject did not solve or solved incorrectly in the first cycle
Now I have a variable Exp_Stimuli, which contains the task (for example, “air, earth, magic”), and a variable Exp_corr, which contains the answer to the task (for example, [‘ball’, ‘ball’, ‘BALL’, ‘BALL’, ‘Ball’, ‘Ball’]). I want the program to check at the first stage whether the subject solved the problem correctly. In the second cycle, only unsolved and incorrectly solved tasks should be shown to the subject.
Please help me with the code - which one and where to write it. I tried different options, nothing works :frowning:
What i’m trying to achieve:
the subject solves the problem - sees the conditions on the screen and enters the answer with the help of a Textbox and so 40 times, after that a break, at the second stage the subject solves those tasks that he did not solve or solved incorrectly at the first stage

I wrote this code in a loop with the first stage:
before experiment:

#creating an empty list for unsolved tasks
unresolved_tasks = []

end routine:

#getting the subject's response from the Textbox component
answer = exp_textbox.text
#comparing the answer with the correct
if answer != Exp_corr_answ:
#if the answer is incorrect, add the task to the list of unsolved
unresolved_tasks.append(Exp_Stimuli)

I wrote this code in a loop with the second stage:

begin routine:

for Exp_Stimul in unresolved_tasks:
# check if the current task is in the list of unsolved
if Exp_Stimul not in unresolved_tasks:
# if the task is not in the list, skip it
continueRoutine = False
else:
# if the task is in the list, delete it from the list
unresolved_tasks.remove(Exp_Stimul)

Now the program at the second stage shows me only the last unsolved problem, which was at the first stage. How to fix it? What could be the mistake?

I’m not sure what you are trying to do in the second routine.
first you loop over all of the failed tasks
for Exp_Stimul in unresolved_tasks:
then you check if the first failed task in unresolved_tasks is in unresolved_tasks (well, of course it will be)
if Exp_Stimul not in unresolved_tasks:

Are you sure that you want the for list to be unresolved_tasks? Seems like you are just removing tasks from the unresolved_tasks list in a for loop at the beginning of your routine.

Maybe this will fix it?
if Exp_Stimul not in unresolved_tasks:
#if the task is not in the list, skip it
continueRoutine = False
else:
#if the task is in the list, delete it from the list
unresolved_tasks.remove(Exp_Stimul)

Also, try adding a print when the task is added to the unresolved list, and then print out all of the unresolved list just before the for loop in the second routine.

You could also share the compiled python script and we could see more of what you are trying to do.

Thanks for your answer! I tried your way, but nothing has changed. In the second cycle, the last task from the first cycle is now being repeated. The program does not seem to see the list of unsolved problems and cannot take values from it.
I didn’t quite understand about adding a print when the task is added to the unresolved list, and then print out all of the unresolved list just before the for loop in the second routine. How should I do that?
Sorry for my stupid questions, I’m just starting my way into PsychoPy

Share my python script, if you can, please take a look
experiment.py (161.5 KB)

Have a look at my Repeat Subset online demo from PsychoPy Online Demos

Repeat Subset code | try it

Adds errors made during the first loop to a list which used by the second loop, so that only incorrect trials are repeated.

Thank you so much for the answer! I did it all right!

I used this code in End Routine

answer = asp_textbox.text

if answer:
# If entered, then check if it is contained in the list of correct answers
if answer not in Exp_corr_answ:
# If it is not contained, then it is an error, and we add the repetition number to the repeatRows list
repeatRows.append(trials.thisIndex)
else:
# If you haven't entered it, then we also add the repetition number to the repeatRows list
repeatRows.append(trials.thisIndex)

I really appreciate all your help!