Code for correct response with typed answers

Hello,

I am working on a routine where participants hear pairs of words and response by typing in all the pairs where both words begin with the same letter.

I want to code for correct answer. I am not providing feedback during the trials (except the practice trials). How could I code this in psychopy so I don’t to do extra work later when I’m analyzing my data?

Hi @sarahnpope, could you give more details on how you built the routine so far? How are responses given? Are all pairs typed into one text box?

1 Like

Hi, yes. Sorry about that missing info. I’m still getting used to psychopy and interacting on this forum.

Response are given in the same textbox, so yes all pairs are typed into the same textbox. The practice block has 2 correct pairs and all other blocks have 5.

So the respondent would write all 10 words in sequence, separated by commas?

I am instructing them to format it in pairs so bunny-baby, cat-cactus

Is the order of the two words important? Would it also count as correct if I write baby-bunny, even if the stimulus was bunny-baby?

That would be correct. The order of the pairs is not important

Here is some code that should do what you need

# examples
correct_str = "baby-bunny, cat-camel"
response_str = "baby-bunny, cat-can, bunny-baby, cactus-canada"

# set counter to 0
correct_counter = 0

# reformat correct responses
correct = []
for i in correct_str.replace(" ", "").split(','):
	correct.append(sorted(i.split('-')))

# reformat given responses
response = []
for i in response_str.replace(" ", "").split(','):
	response.append(sorted(i.split('-')))

# check how many correct responses are in the given responses
for i in correct:
	if i in response:
		correct_counter = correct_counter + 1 
  • correct_str is the variable in your conditions file, that specifies the correct responses. I needs to be written in the above format
  • response_str is the response that your participant gave
  • correct_counter counts how many of the correct answers are in the response your participant gave and has to be saved for each trial.

Be aware that this fails as soon as your respondents don’t use the instructed format for their responses or make spelling mistakes!