# Giving feedback for four potential answers

**URL:** <https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320>\
**Category:** Coding\
**Tags:** feedback\
**Created:** [August 8, 2022, 2:33pm UTC](https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320 "2022-08-08T14:33:23Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![caitlin1046](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@caitlin1046](https://discourse.psychopy.org/u/caitlin1046)\
**Post date:** [August 8, 2022, 2:33pm UTC](https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320/1 "2022-08-08T14:33:24Z")

</div>

Hi there,  
I’m really new to Psychopy and coding. I’m creating an experiment whereby an arrow is displayed on top of an image, following which participants must use arrows on the keyboard to identify which direction the arrow is facing.  
I want practice trials that give feedback after the participants have given their answer as to whether it is correct or incorrect. I have used the below code:

```auto
if key_resp_8 == corrAns:
     msg = 'Correct'
else:
   msg = 'Sorry, Incorrect'

```

The error message I am seeing is ‘msg not defined’ and ‘corrAns isn’t defined’  
I have defined msg in my text box and corrAns in my excel spreadsheet (see below);

![loop1](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/4/5/454b7d6fe7c18d9cf0e719f032234738ba625d79.png)

Any help would be greatly appreciated

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [August 8, 2022, 2:41pm UTC](https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320/2 "2022-08-08T14:41:35Z")

</div>

Hello,

define

```auto
msg='doh!' #if this comes up we forgot to update the msg!

```

in a begin experiment tab.

then use

```auto
if not key_resp_8.keys :
    msg="Failed to respond"
elif key_resp_8.corr:
    msg = 'Correct'
else:
    msg = 'Sorry, incorrect'

```

in the relevant begin tab.

See also here [Builder - providing feedback — PsychoPy v2022.2.3](https://psychopy.org/recipes/builderFeedback.html)

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![caitlin1046](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@caitlin1046](https://discourse.psychopy.org/u/caitlin1046)\
**Post date:** [August 9, 2022, 9:05am UTC](https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320/3 "2022-08-09T09:05:00Z")

</div>

Hi Jens,  
Thank you for your help!  
The problem I’m now facing is that the message ‘doh’ is displaying for the first trial and then for the subsequent trials, it seems that it is just randomly selecting which message to present rather than showing correct for correct answers and vice versa. I’m not sure if it is an issue with how I have laid my spreadsheet out? (see image above).

Thanks again,  
Caitlin

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [August 9, 2022, 9:33am UTC](https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320/4 "2022-08-09T09:33:25Z")

</div>

Hello Caitlin

it might be that the order of the text-component and the code-component is wrong. The code-component has to appear before the text-component of the feedback message.

See the attached example.

[Feedback.psyexp](https://discourse.psychopy.org/uploads/short-url/h6rVe66Fb9zZdrGdZcxb3JQzszW.psyexp) (12.5 KB)  
[loopTemplate1.xlsx](https://discourse.psychopy.org/uploads/short-url/fPV2zXnvRVjToVTHc0NMQjLETwB.xlsx) (17.8 KB)

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![caitlin1046](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@caitlin1046](https://discourse.psychopy.org/u/caitlin1046)\
**Post date:** [August 9, 2022, 10:37am UTC](https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320/5 "2022-08-09T10:37:07Z")

</div>

It’s working!! Thank you so much 🙂

---

<div class="post-metadata">

**Author:** ![caitlin1046](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@caitlin1046](https://discourse.psychopy.org/u/caitlin1046)\
**Post date:** [August 19, 2022, 1:28pm UTC](https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320/6 "2022-08-19T13:28:24Z")

</div>

Apologies! I decided to add more images to the experiment. I did not think this would impact my feedback loop. However, it is stating every answer is incorrect and I can’t see a reason why. I’ve changed nothing regarding the correct answer, merely added more images.  
I really appreciate your help!

 ![Screenshot 2022-08-19 at 14.26.03](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/a/ba6d22762ac6bae6b0ff921f401a22f173f55d74.jpeg)  
 ![Screenshot 2022-08-19 at 14.26.09](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/b/a/ba5dcef0b0437335a4d95a02ccabcb94f771d92e.jpeg)  
 ![Screenshot 2022-08-19 at 14.26.20](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/5/6/5659a039b8e61b47d840906adbe40b5d66ef56c2.jpeg)  
 ![Screenshot 2022-08-19 at 14.26.21](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/6/c64e38fcd1a6e41f5551a543baf24422fff0def7.jpeg)  
 ![Screenshot 2022-08-19 at 14.26.25](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/c/2/c29f9c90eea7c377d383617b44342419bc9919fc.jpeg)

---

<div class="post-metadata">

**Author:** ![caitlin1046](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@caitlin1046](https://discourse.psychopy.org/u/caitlin1046)\
**Post date:** [August 19, 2022, 1:29pm UTC](https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320/7 "2022-08-19T13:29:40Z")

</div>

My spreadsheet also.

 ![Screenshot 2022-08-19 at 14.28.58](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/6/6/66c80f15027416a49d05167eba52a1ab04b31e3e.png)

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [August 19, 2022, 10:13pm UTC](https://discourse.psychopy.org/t/giving-feedback-for-four-potential-answers/30320/8 "2022-08-19T22:13:56Z")

</div>

Hello,

did you set corrAns in the response-key-component? Adding more stimuli does not impact the feedback.

BTW, initializing msg goes to the Begin Experiment tab. However, that shouldn‘t impact your feedback.

Best wishes Jens
