'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 :
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 1:[1]
Fixed code:
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")
Ouput
not OK
not OK
not OK
not OK
OK
OK
OK
OK
OK
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TheCoder1001 |
