# How to put condition in Text component?

**URL:** https://discourse.psychopy.org/t/how-to-put-condition-in-text-component/7676
**Category:** Builder
**Created:** [May 8, 2019, 6:39pm UTC](https://discourse.psychopy.org/t/how-to-put-condition-in-text-component/7676 "2019-05-08T18:39:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![AliBahaari](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/alibahaari/32/4236_2.png) [@AliBahaari](https://discourse.psychopy.org/u/AliBahaari)
#### Post date: [May 8, 2019, 6:39pm UTC](https://discourse.psychopy.org/t/how-to-put-condition-in-text-component/7676/1 "2019-05-08T18:39:42Z")

</div>

Hello, I average SSDs and I show it to the subject. It works as you can see in the image below :

 ![Text](https://us1.discourse-cdn.com/flex002/uploads/psychopy/original/3X/a/0/a082610df26c21d44b6dea52e42301ec459dff60.png)

But I actually need to put a condition that if average is greater than a number show the subject a text beside the average number. How can I do that?  
For example :

```auto
if np.average(trialsArray_1) > 100 :
    # You reaction time is GOOD because it is 105.05.
else :
    # You reaction time is BAD because it is 95.05.

```

---

<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: [May 8, 2019, 11:25pm UTC](https://discourse.psychopy.org/t/how-to-put-condition-in-text-component/7676/2 "2019-05-08T23:25:54Z")

</div>

The expression in the code component can only really be one line long. So it is probably easiest here to insert a code component above the text component, and in the “each routine” tab, insert multiple lines of code, based on the example you give above.

i.e. in the code, you create a variable to hold the message you want to display:

```auto
average = round(np.average(trialsArray_1))

if average > 100 :
    feedback = f'Your reaction time is GOOD because it is {average}.'
else:
    feedback = f'Your reaction time is BAD because it is {average}.'

```

Then in the text component itself, just put:

```
$feedback

```

in the text field, set to update on very routine.

f-strings are a feature of Python 3, so you need the Python 3 version of PsychoPy for this code to work. Otherwise, use some of the older Python 2-compatible ways of formatting strings with variables.

Use the `round()` function as needed to get consistent formatting of your average.

---

<div class="post-metadata">

### Author: ![AliBahaari](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/alibahaari/32/4236_2.png) [@AliBahaari](https://discourse.psychopy.org/u/AliBahaari)
#### Post date: [May 9, 2019, 8:05am UTC](https://discourse.psychopy.org/t/how-to-put-condition-in-text-component/7676/3 "2019-05-09T08:05:09Z")

</div>

As always great help. Thank you @Michael . 😊
