Ad

Multiple Condition If Fonction Inside A For Loop

- 1 answer

i'm browsing SO and i can't find a solution to my problem, so i made a post.

I try to make a For loop with a If statement inside that have multiple conditions (at least 3) but it does not work and i can't wrap my head around it... i tried lot of things but nothing seams to work.

here is my code, simplified because in my actual code the values for a, b, c and d are random :

    a=[1]
    b=[2]
    c=[3]
    d=[0,1,2,3,4,5,6,7,8]
    
    for i in d:
        if d>a and\
           d>b and\
           d>c:
            print("OK")
        else:
            print("not OK")

But no matter what i try, i always get this output :

not OK
not OK
not OK
not OK
not OK
not OK
not OK
not OK
not OK

Thank you for your help

Ad

Answer

Do you mean this :

a = 1
b = 2
c = 3
d = [0, 1, 2, 3, 4, 5, 6, 7, 8]

for i in d:
    if i > a and i > b and i > c:
        print("OK")
    else:
        print("not OK")

not OK
not OK
not OK
not OK
OK
OK
OK
OK
OK
Ad
source: stackoverflow.com
Ad