# Data file does not indicate whether a response is correct or incorrect

**URL:** <https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491>\
**Category:** Coding\
**Created:** [January 7, 2020, 10:04pm UTC](https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491 "2020-01-07T22:04:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ryan](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Ryan](https://discourse.psychopy.org/u/Ryan)\
**Post date:** [January 7, 2020, 10:04pm UTC](https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491/1 "2020-01-07T22:04:05Z")

</div>

I am using version 3.0.5, and on my conditions file I have a “corrAns” column, but when I tell the program to “store correct” and put $corrAns for what the correct answer should be, it doesn’t display whether the participant’s answer is correct on the data sheet or not. Furthermore, it returns this code:

# -------Ending Routine “test”-------

```
for thisComponent in testComponents:
    if hasattr(thisComponent, "setAutoDraw"):
        thisComponent.setAutoDraw(False)
# check responses
if testresponse.keys in ['', [], None]: # No response was made
    testresponse.keys=None
    # was no response the correct answer?!
    if str(corrAns).lower() == 'none':
       testresponse.corr = 1; # correct non-response
    else:
       testresponse.corr = 0; # failed to respond (incorrectly)
# store data for tests (TrialHandler)
tests.addData('testresponse.keys',testresponse.keys)
tests.addData('testresponse.corr', testresponse.corr)
if testresponse.keys != None: # we had a response
    tests.addData('testresponse.rt', testresponse.rt)

```

Even when no response is given, a 0 is still displayed in the “testresponse.corr” column. Any suggestions?

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [January 7, 2020, 11:26pm UTC](https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491/2 "2020-01-07T23:26:29Z")

</div>

You should probably show us a screenshot of your keyboard component’s settings, and some example content from your conditions file `corrAns` column.

---

<div class="post-metadata">

**Author:** ![Ryan](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Ryan](https://discourse.psychopy.org/u/Ryan)\
**Post date:** [January 8, 2020, 1:49am UTC](https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491/3 "2020-01-08T01:49:39Z")

</div>

Sure thing,

 ![Screen Shot 2020-01-07 at 8.49.01 PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/c/ecfe993978bce2988f11912a15e7f67f6f8d539f.png)  
 ![Screen Shot 2020-01-07 at 8.47.43 PM](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/e/1/e156bb5fa54496f06e552f6e93e839303616b2ef.png)

Is this what you mean?

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [January 8, 2020, 3:54am UTC](https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491/4 "2020-01-08T03:54:08Z")

</div>

> [@Ryan](#):
>
> Is this what you mean?

Yes.

> [@Ryan](#):
>
> I have a “corrAns” column, but when I tell the program to “store correct” and put $corrAns for what the correct answer should be

There is zero correspondence between the 6 allowed keys and the multi-character words in the `corrAns` column, so the answer can never be correct.

Also, you have it set to collect multiple keypresses by “Store: all keys”. This generally doesn’t make it possible to compare responses to a stored answer, which both need to be single characters.

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [January 8, 2020, 3:56am UTC](https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491/5 "2020-01-08T03:56:52Z")

</div>

Oh, wait a moment, you’re intending for people to type out a whole word (and presumably allow for all of the letters in the alphabet)?

The keyboard component doesn’t work like that. It stores a list of keypresses rather than concatenating them into a single string, so you’d need to use some code to process the list. You’d probably also need to give onscreen real-time feedback of typing, as a lot of responses will be contaminated by typos.

There are a few examples of that if you search this forum, e.g.

> [@Displaying Typed Words on Screen during a Routine](https://discourse.psychopy.org/t/displaying-typed-words-on-screen-during-a-routine/6414):
>
> What are you trying to achieve?: I’m trying to create an experiment on builder which will allow participants to type one word at a time then have the word they recalled moved to the upper right hand corner (essentially so they can see a list of all of the words they recalled). What did you try to make it work?: Since I’m using Builder, I tried to use the “InputText” snippet I found online: [https://github.com/jacanterbury/PsychoPy-snippets](https://github.com/jacanterbury/PsychoPy-snippets) Now that did work, as it should, but I want to change…

and I think you could even download a working example from here, to modify as needed:

> **[Sign in](https://gitlab.pavlovia.org/users/sign_in)**
>
> Sign In/Register

---

<div class="post-metadata">

**Author:** ![Ryan](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Ryan](https://discourse.psychopy.org/u/Ryan)\
**Post date:** [January 8, 2020, 4:14am UTC](https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491/6 "2020-01-08T04:14:54Z")

</div>

Are you referring to a code that displays the text as it is being typed so the subject can see what he is typing? If so, I already have that.

> [@Michael](#):
>
> There is zero correspondence between the 6 allowed keys and the multi-character words in the `corrAns` column, so the answer can never be correct.
> 
> Also, you have it set to collect multiple keypresses by “Store: all keys”. This generally doesn’t make it possible to compare responses to a stored answer, which both need to be single characters.

Are you saying that for an answer to be listed as correct, it has to be only one character?

> [@Michael](#):
>
> so you’d need to use some code to process the list.

Where can I find a code like this?

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [January 8, 2020, 4:32am UTC](https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491/7 "2020-01-08T04:32:46Z")

</div>

> [@Ryan](#):
>
> If so, I already have that.

You can’t be using that sort of custom code _and_ use the keyboard component to do things as well: the two will conflict. i.e. either the keyboard component or your custom code will detect the keypresses. Whichever one gets there first, wins. So you should probably just delete the keyboard component and have everything done via code.

> [@Ryan](#):
>
> Where can I find a code like this?

You already have it, as your custom typing code should be doing that already (i.e. collating all the keypresses together into a single string variable).

You would just need to make the comparison explicitly yourself. e.g. at the end of the routine, code like this:

```auto
if your_response_variable_name == corrAns:
    # store in the data file manually:
    thisExp.addData('answer_correct', 1) # or True or 'Yes', or whatever
else:
    thisExp.addData('answer_correct', 0)

```

---

<div class="post-metadata">

**Author:** ![Ryan](https://avatars.discourse-cdn.com/v4/letter/r/a8b319/32.png) [@Ryan](https://discourse.psychopy.org/u/Ryan)\
**Post date:** [January 8, 2020, 5:26am UTC](https://discourse.psychopy.org/t/data-file-does-not-indicate-whether-a-response-is-correct-or-incorrect/10491/8 "2020-01-08T05:26:31Z")

</div>

So I should get rid of the keyboard component but retain all the code that goes along with it?

> [@Michael](#):
>
> You already have it, as your custom typing code should be doing that already (i.e. collating all the keypresses together into a single string variable).
> 
> You would just need to make the comparison explicitly yourself. e.g. at the end of the routine, code like this:
> 
> ```auto
> if your_response_variable_name == corrAns:
> # store in the data file manually:
> thisExp.addData('answer_correct', 1) # or True or 'Yes', or whatever
> else:
> thisExp.addData('answer_correct', 0)
> 
> ```

When I added this in, I used “recallresp” as the variable name, as that is the column in the data sheet where all the letters in the subject’s response were joined to make a word, but when I try to run the experiment now it says that recallresp is undefined. Should I use something like .join(testresponse.keys)? Also, if I put this in a code component, which heading (like the “begin experiment”, “begin routine” etc.) should it go under?
