Return specific number for a specific range of values

hello!

I’m trying to construct a python node to perform the following condition:

if the input number is between the range 30-45, return 1

if the input number is between the range 45-60, return 2

if the input number is between the range 60-75, return 3 and so on.

I’m struggling with the “so on” part. I at least need the range until 900-915, return XXX.

Any help would be appreciated.

So you want to take the number, divide by 15, subtract two, and round down?

Untested in Dynamo but works on my browser.

import math
groupKeys = [ math.floor( n / 15 - 2 ) for n in initial values ]
1 Like

Thanks for your reply.
This logic almost solves the problem. But, in some places it requires, rounding “UP” and in a few places, Rounding down. If the values are closer to the lower extreme(31 in the first case for example), this becomes an issue. Maybe I’m wrong.

@Dynamo_Noob

# 30-44 : 1
# 45-59 : 2
# 60-74 : 3
# 75-89 : 4
# .....

import math
OUT = [ math.floor( n / 15 ) - 1 for n in IN[0] ]
1 Like

works perfectly! thank you! wish i could mark both answers as the solution.

1 Like

This looks like something I need for my problem. But not familiar with writing the Code, or maybe I need to see more information. My ranges and output look something like this.
Range between 1-25 : 1, 26-50 :2… The input is a number I am pulling from a Grand Total Count from a schedule. Not sure where to begin to setup.

@jtmiller Try this:

3 Likes

Thanks for the Reply back. And thanks for the tip. That at least get me pointed in a direction to do some more searching and learning. Not familiar with the coding part of Dynamo, just been using nodes. So these Math functions are nee to me. What you show will be helpful. Thanks again.

@jtmiller Updated the image to get the same result but using node.

1 Like