Python or code block ,use if_else ,can't done,correct me!

need for your help thanks!
Q1:HOW TO correct my python code
dataEnteringNode = IN
w = IN[0]
arr =
j=0
#condition
for i in w:
if i < 900:
arr[j] = ‘C5’
elif i >= 900 and i < 1500:
arr[j] = ‘C6.3’
elif i >= 1500 and i < 2501:
arr[j] = ‘C8’
else:
arr[j] = ‘C10’
#Assign your output to the OUT variable.
OUT = arr

Q2:IS the code block can’t support array list?
AND why the answer is" 888" not “1” or “2”

Q3:how to add "sc >250 and sc <250 "

many thanks!!!

Right now you have arr as an empty list then your code tries to apply a value at arr[0] which doesn’t exist. I think you’re actually wanting to append the value to your empty list.

 arr.append('C5')
2 Likes

Hello @caoyecheng,

Is this what you are looking for?

numbers = IN[0]

results = []

for number in numbers:
    if number < 900:
        results.append("C5")
    elif number >= 900 and number < 1500:
        results.append("C6.3")
    elif number >= 1500 and number < 2501:
        results.append("C8")
    else:
        results.append("C10")

OUT = results
2 Likes

thanks!it works

1 Like

thanks for your help

and about Q3 – The code block,i use" &&" insted of “and” : sc>250 && sc <500,
it can run.but still only for one number,do no support array/ list

There’s no need for an imperative function. A simple If statement will do.
image
[condition] ? [result if true] : [result if false]

4 Likes

it is a better way. thanks!!!

1 Like