Probably the easiest way to do this would be to just list what you deem to be acceptable in your correct answer column. So your column would look like this:
Unfortunately I have over 500 words and that would be very lengthy. I actually did come up with a solution, and thought that I would share it. I switched over to coder view and implemented this code.
if text_11.status == STARTED and t >= frameRemains:
text_11.setAutoDraw(False)
if text_11.status == STARTED: # only update if drawing
text_11.setText(corrAns, log=False)
countForPerc = 0
wordSizeOfAns = len(corrAns) #Get the size of ans
percentNeeded = wordSizeOfAns * 0.8 #number for percent right needed based off size of word
totalForGreen = int(round(percentNeeded)) #round to compare for count
#If the number changes..may need to make sure it round down and not to nearest.
for i, s in enumerate(difflib.ndiff(TypeIn.keys, corrAns)): #function for diff in words
if s[0]=='': continue
elif s[0]=='-' or s[0]=='+':
countForPerc += 1
else: continue
correctPercEntered = False
if countForPerc <= totalForGreen: #if the messup is <= 80%, allow
correctPercEntered = True
if correctPercEntered == True:
text_11.color = ('Green')
else:
text_11.color = ('Red')
questions.addData('correctPercEntered',correctPercEntered)
This way, if the participant response has an 80% overlap with the correct answer, then they will get feedback that their response is correct.
I am trying to replicate what @Lzgordon and @Oli did, but running into an error message:
if key_resp_2.keys == list(corrAns):
NameError: name ācorrAnsā is not defined
(The error is referring to the bit of code in the end of the routineā¦)
if key_resp_2.keys == list(corrAns):
msg = āCORRECTā
trials.addData(ācorrectā, 1) #where trials is the name of the loop
trials.addData(āresponseā, āā.join(key_resp_2.keys))
My excel file for conditions is attached to the loop, and looks like this. It displays the $stim just fine, so I canāt understand why the corrAns bit is having problems.
Sorry to revive this thread but I am trying something similar but easier. I am presenting a string of characters to participants and asking them to simply count the number of characters that are in bold. The sequence is actually repeated over and the counting task is a means of sustaining attention to that sequence order. I wanted a feedback screen to test their cumulative count and have tried to use the code below:
if key_resp_2.keys == corrAns:
msg = 'Correct'
else:
msg = 'Incorrect, the answer was %s' %corrAns
I then have an Excel spreadsheet with one column corrAns with a single answer in it. Within this loop I have the question screen during which the participant inputs their answer. After this is the feedback screen with the code above. The training runs fine but no matter what number is put in, the response screen always says that the answer is wrong, even if I constrain the input button on the question screen to the right answer. I cannot figure out how to get around it. Any ideas?
I would also like to have a double digit answer as my repeated sequence will be 66 characters long so Iād like an answer to be >10 but <25. How do I code the feedback screen to pick up on the double digits?
Sorry it also comes up with this warning message in the PsychoPy output as well:
FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
if key_resp_2.keys == corrAns:
hi, @asucha1, if you mean how to show a key response, you have to add a code component and a text component. the text component (showresponse) you just leave blank.
keys = event.getKeys()
if 'escape' in keys:
core.quit() # So you can quit
else:
if keys:
if keys[0] == 'space':
textFill += ' ' # Adds a space instead of 'space'
elif keys[0] == 'backspace':
textFill = textFill[:-1] # Deletes
elif keys[0] in allLetters:
textFill+=keys[0] # Adds character to text if in alphabet.
showresponse.setText(textFill) # Set new text on screen
The code provided by @smile667 works great for letters but I do not need participants to enter letters, just numbers. Is there a way to adapt the code to allow participants to enter digits?
# Begin Experiment
allNums = ['1','2','3','4','5','6','7','8','9','0']
screen_text = ''
# Each frame
key_estimate = event.getKeys()
if 'escape' in key_estimate:
core.quit() # So you can quit
else:
if key:
if key [0] == 'backspace':
screen_text = screen_text[:-1] # Deletes backspace
if len (screen_text) > 2: #set how many digits you want from participants
screen_text = screen_text[:-1]
elif key_estimate [0] in allNums:
screen_text+=key_estimate[0] # display numbers
if len (screen_text) > 2:
screen_text = screen_text[:-1]
elif key [0] == 'return':
if len (screen_text) >= 0 and int(screen_text) <= 59: # do not allow them to enter number greater than 59
continueRoutine = False
else:
continueRoutine = True
# End routine
thisExp.addData ("final_estimate", screen_text)