# I want to write multiple if elif conditional which check if the value is greater than some number or less than some number or between two numbers

**URL:** <https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106>\
**Category:** Ask for Help\
**Created:** [August 16, 2023, 8:01pm UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106 "2023-08-16T20:01:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ikigai\_Edu](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ikigai_edu/32/62979_2.png) [@Ikigai\_Edu](https://community.glideapps.com/u/Ikigai_Edu)\
**Post date:** [August 16, 2023, 8:01pm UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/1 "2023-08-16T20:01:33Z")

</div>

This is the example python code. I want to write that into Glide column. For example, there is a temperature column that user input. Then I want to use that column to create new column with the below conditions.

```python
#Temperature
def news_temperature(score):
    if score <= 35.0:
        new_score = 3
    elif (score >= 35.1 and score <= 36.0) or (score >= 38.1 and score <=39.0):
        new_score = 1
    elif score >= 36.1 and score <= 38.0:
        new_score = 0
    elif score >= 39.1:
        new_score = 2
    return new_score

```

---

<div class="post-metadata">

**Author:** ![Eric\_Penn](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/eric_penn/32/73888_2.png) [@Eric\_Penn](https://community.glideapps.com/u/Eric_Penn)\
**Post date:** [August 16, 2023, 8:07pm UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/2 "2023-08-16T20:07:20Z")

</div>

Try it with Java script and the Java script column.

Replace score with p1

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [August 17, 2023, 1:36am UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/3 "2023-08-17T01:36:51Z")

</div>

The following in an if-then-else column should work:

- If Score \>= 39.1, then 2
- If Score \>= 38.1, then 1
- If Score \>= 36.1, then 0
- If Score \>= 35.1, then 1
- Else 3

 ![CleanShot 2023-08-17 at 09.33.03@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/4/d414ad610f33f56dd25d545821a509cabdba4bcc.jpeg)

---

<div class="post-metadata">

**Author:** ![Ikigai\_Edu](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ikigai_edu/32/62979_2.png) [@Ikigai\_Edu](https://community.glideapps.com/u/Ikigai_Edu)\
**Post date:** [August 17, 2023, 4:16am UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/4 "2023-08-17T04:16:53Z")

</div>

I have tried that but still cannot get the answer.

This is my javascript code

```javascript
var newsScore;

if (p1 <= 35.0) {
    newsScore = 3;
} else if ((p1 >= 35.1 && p1 <= 36.0) || (p1 >= 38.1 && p1 <= 39.0)) {
    newsScore = 1;
} else if (p1 >= 36.1 && p1 <= 38.0) {
    newsScore = 0;
} else if (p1 >= 39.1) {
    newsScore = 2;
}

newsScore;

```

I didn’t get the return value in my new column.

---

<div class="post-metadata">

**Author:** ![Ikigai\_Edu](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ikigai_edu/32/62979_2.png) [@Ikigai\_Edu](https://community.glideapps.com/u/Ikigai_Edu)\
**Post date:** [August 17, 2023, 4:22am UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/5 "2023-08-17T04:22:00Z")

</div>

Your example does work. I just need to put additional condition for when the input value is blank. Thank you very much for your help. So what I would like to understand is that we should write the conditionals starting from the biggest value?

Also may I know if we want to do some kind of machine learning model prediction, can we do that. For example, the input features will be the first 6-8 column features, then we will do some kind of model prediction on the last column. Can we do that?

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [August 17, 2023, 4:37am UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/6 "2023-08-17T04:37:03Z")

</div>

> [@Ikigai\_Edu](#):
>
> So what I would like to understand is that we should write the conditionals starting from the biggest value?

Either way would work. If you did it from lowest to highest, then you would just reverse the comparison operators.

> [@Ikigai\_Edu](#):
>
> Also may I know if we want to do some kind of machine learning model prediction, can we do that. For example, the input features will be the first 6-8 column features, then we will do some kind of model prediction on the last column. Can we do that?

I’m not too sure about that, can you give a practical example with an expected result?

---

<div class="post-metadata">

**Author:** ![Ikigai\_Edu](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ikigai_edu/32/62979_2.png) [@Ikigai\_Edu](https://community.glideapps.com/u/Ikigai_Edu)\
**Post date:** [August 17, 2023, 4:44am UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/7 "2023-08-17T04:44:28Z")

</div>

![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/6/7/671f0a253df35fde0330824125f4cf62f9180eb7.png)

For example, this kind of case. There will be multiple column structured data, then we will do some kind of model prediction. I saw some tutorial videos of building a chatbot app with OpenAI api but I am not sure if we have multiple input features, can we do model prediction? I haven’t tried that. Thank you very much again for your answer and prompt reply.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [August 17, 2023, 4:50am UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/8 "2023-08-17T04:50:40Z")

</div>

I’d say it’s possible, but you’d need to design some rules and craft an appropriate prompt for your AI.

The Glide Blog has quite a few recent articles and tutorials related to using AI in GlideApps. I’d suggest having a browse through there, and you might get some ideas.

> **[Glide Apps No-Code Blog](https://www.glideapps.com/blog)**
>
> The latest developments from Glide

---

<div class="post-metadata">

**Author:** ![Ikigai\_Edu](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/ikigai_edu/32/62979_2.png) [@Ikigai\_Edu](https://community.glideapps.com/u/Ikigai_Edu)\
**Post date:** [August 17, 2023, 6:05am UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/9 "2023-08-17T06:05:43Z")

</div>

Thank you. I will try that.

---

<div class="post-metadata">

**Author:** ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)\
**Post date:** [August 17, 2023, 1:44pm UTC](https://community.glideapps.com/t/i-want-to-write-multiple-if-elif-conditional-which-check-if-the-value-is-greater-than-some-number-or-less-than-some-number-or-between-two-numbers/65106/10 "2023-08-17T13:44:20Z")

</div>

Hola!

Just to tell you why your original code failed: the missing piece is the _**return()**_ function.

> return newsScore

This new version should work just as well as Darren’s suggestion.

```auto
 if (p1 <= 35) 
    return 3;
if ((p1 > 35 && p1 <= 36) || (p1 > 38 && p1 <= 39))  
    return 1;
if (p1 > 36 && p1 <= 38)  
    return 0;
  
return 2 // returns '2' if all checks fail (>39)!!.

```

Saludos!
