Correct answers can continue the task; incorrect answers have to repeat the same task

Hello,

I’m trying to programme a task, where participants see a series of numbers : [1 5 3 8 1] in which each numbers correspond to a letter.

Problem: currently, both the correct and incorrect answers can continue the task

What I’m trying to do:

  1. if it is incorrect, the same number of sequence does not change, the participant have to get the answers correctly in order to continue to the next sequence.
  2. If it is incorrect, you get the message “Incorrect, please try again”, while the correct answers takes participant to the next number of sequence

My code so far:

Greatly appreciate your help!

It’s difficult to (safely) make a loop which truely infinite, but you could make a loop with a number of repetitions participants are unlikely to reach (say, 100) and add code to break this loop early if they get the answer right. This would go in the End Routine tab of a Code Component and would look like this:

if captured_string==correctletters2:
    break

@TParsons

Thank you for your response. I’m trying to set up a display of correct and incorrect answers, as well as the amount of answers achieved in the following codes:
Begin Experiment:

correctnumber = 0 
incorrectnumber = 0
failednumber = 0 
totalnumber = 10

Begin routine:

cursorCounter=0
cursorVariable='|'
captured_string=''
subject_response_finished=False
trial_clock=core.Clock()
correctans=[]
yourans = 0

Each frame:

if cursorCounter >= 10:
    if cursorVariable=='|':
        cursorVariable=' '
    else:
        cursorVariable='|'
    cursorCounter=0
cursorCounter+=1

if subject_response_finished:
    final_response=captured_string
    continueRoutine=False

for key in event.getKeys():
    if key in ['escape']: 
        core.quit()
    elif key in ['delete','backspace']:
        captured_string = captured_string[:-1] 
    elif key in ['period']:
        captured_string = captured_string+'.'
    elif key in ['semicolon']:
        captured_string = captured_string+';'
    elif key in ['space']:
        captured_string = captured_string+' '
    elif key in ['comma']:
        captured_string = captured_string+','
    elif key in ['apostrophe']:
        captured_string = captured_string+"'"
    elif key in ['slash']:
        captured_string = captured_string+'/'
    elif key in ['minus']:
        captured_string = captured_string+'-'
    elif key in ['lshift','rshift','up','down','left','right','return']:
        pass
    else: 
        captured_string = captured_string+key

End routine:

correctletters2=correctletters[0]+correctletters[1]+correctletters[2]+correctletters[3]+correctletters[4]+correctletters[5] #numbers needed to be strings
#captured_string=captured_string[0:6] #6 letters corresponding to 6 numbers 

if captured_string == correctletters2:
    correctans = 2
    correctnumber = correctnumber + 1
    msg='You have achieved :' + str(correctnumber + 1) + '/' + str(totalnumber)
elif not captured_string:
    correctans = 1
    failednumber = failednumber + 1
    msg='You have achieved :' + str(correctnumber - 1) + '/' + str(totalnumber)
    continue_routine = False
else:
    correctans = 0
    incorrectnumber = incorrectnumber + 1
    msg='You have achieved :' + str(correctnumber - 1) + '/' + str(totalnumber)
    continue_routine = False 

print('correctletters', correctletters2)
print('input',captured_string)
print('correctanswer',correctans)

When it’s printed, however, it showed:

correctletters upavbp
input   upavbp 
correctanswer 0

Obviously the correctletters matched the input, but I just don’t understand why correct answer is 0 (supposed to be 1) and on the screen, it shows that I have put in the incorrect answer. Would you be able to help?

What happens if you print just captured_string == correctletters2? Does it show True or False? If it’s False then there must be some subtle difference between the two - maybe some spaces at the beginning or end?

I printed captured_string == correctletters2 and it shows True. I also printed the lengths of the characters and input, they are the same length. I’m not sure why it’s still not giving me the correct and incorrect feedback

What happens when you put a print statement inside the if loop? Like this:

if captured_string == correctletters2:
    print("Reached correct line")
    correctans = 2
    correctnumber = correctnumber + 1
    msg='You have achieved :' + str(correctnumber + 1) + '/' + str(totalnumber)

Does it print that? If so then there must be something else changing the value of correctans between here and the original print statements…

Interesting… it has given me this:
Reached correct line
True
correctletters ydjwpk
input ydjwpk

So it is reaching the correct line. I feel that I am nearly there, but I’m still not sure where the problem is

1 Like

I fixed it!! Thanks so much @TParsons!!

1 Like

Out of interest, what was it?

Hi @TParsons:
The correct code is in the following:

> if captured_string == correctletters2:
>     correctans = 2
>     correctnumber = correctnumber + 1
>     msg='You have achieved :' + str(correctnumber) + '/' + str(totalnumber)
> elif not captured_string:
>     correctans = 1
>     failednumber = failednumber + 1 
>     msg = 'Empty response! You have achieved:' + str(correctnumber) + '/' + str(totalnumber)
> else:
>     correctans = 0
>     incorrectnumber = incorrectnumber + 1
>     msg = 'Incorrect! You have achieved:' + str(correctnumber) + '/' + str(totalnumber)
> 
> if correctnumber == totalnumber:
>         break

I’m not sure where exactly went wrong with the previous code because it is not that different. However, the logic is very similar.

2 Likes