Get minimum and maximum value using if statement

I’m trying to get the minimum and maximum values using the IF statement. If the two values are negative, then I need the minimum value; if the two values are positive, then I need maximum value. I hope my IF formula looks good when I given the input of a double (data type) value in a code block it’s working good, but when converted into a list, I am getting minimum value instead of maximum value.

input = IN[0]

listCount=len(input)

negativeBool=[]

for a in input:
    if a <0:
        negativeBool.append(True)

if len(negativeBool) == listCount:
    OUT=min(input)
else:
    OUT=max(input)
1 Like

Or if you want it to get the lowest value if any value is negative then the following is what is needed

input = IN[0]

listCount=len(input)

negativeBool=[]

for a in input:
    if a <0:
        negativeBool.append(True)

if any(negativeBool):
    OUT=min(input)
else:
    OUT=max(input)
1 Like

@Brendan_Cassidy Thanks for your quick replay.
But having the same result.

That’s because you’re not handling lists in your code. You’re returning the final else condition because you’re comparing a list instead of a number for the other conditions, so they both fail.

You need to iterate the values in your list and compare them, then append the results to an output list.

for e1,e2 in zip(ele1,ele2):
    [conditional statements with e1,e2]
1 Like

Thanks @Nick_Boyts, now it’s working good :grinning: