Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Multiple condition if fonction inside a for loop

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    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

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading