Value falls between

hello guys
i have list of values and each value equals a parameter of visibilty
for ex list 0 =19,34
1 =20,22
2 =27,66
and if the value between 19<X<20 then =bananas, if value between 20<X<21 then =tomatos etc…
see below for more explanations

from the image you need to round down to the next integer right ?

If this is the case then this can help (I need to point out that I’m a noob at python) :

import math

A = IN[0]
Result =

for i in A :
Result.append(math.floor(i))

OUT = Result

Thank you for your help
but in my case the result is a string ,i have “19meters” and not a integer

@dr.hybride Try this:

thank you it’s good idea
but i really need to use a formula like this IF x between [10,20] then = bananas
IF x between [20,30] then = tomatos
IF x between [10,20] then = chips etc…

why ? is it because the type is string ? because you have the string to number node to change strings to numbers and then you can change it the other way around…

The formula you are describing is fairly easy to do with python with a for loop and then a number of ifs, however this will be limited to a predifined range, you need to define it so that it will cover all your possible cases… are you starting from 0 and going up to what ?

You can do it in dynamo with the if node or you can do it by defining a function directly with design script : Functions | The Dynamo Primer

I would use an in line design script statement to process from below the lowest range to above the highest range, thusly:

    a< 10 ? 1stValue :
    a< 20 ? 2ndValue :
    a< 30 ? 3rdValue :
    4th value;

you are right
i need to define for each lengths but it’s not a lot .
i tried but i fail

@dr.hybride It’s failing because there are no indents in your Python code.
I would recommend you to go for the DesignScript approach as suggested by @JacobSmall
If you still want to go the Python route you can do so as suggested below.

DesignScript

x<20 && x>=19?"Chocolate":
x<19 && x>=18?"Bananas":
x<18 && x>=17?"Chips":
"Check Value";

Python

out = []

for i in IN[0]:
	if 19 <= i < 20:
		out.append("Chocolate")
	elif 18 <= i < 19:
		out.append("Bananas")
	elif 17 <= i < 18:
		out.append("Chips")
	else:
		out.append("Check Value")
		
OUT = out
2 Likes

great , very nice thank you very much

1 Like