Reputation: 195
what am i doing wrong with my if statement that it doesn't recognise if an element in a is equal to 0? what i am attempting to print is for ever 0 the program prints .
and for ever 1 #
. cheers.
a=[0,0,1,0,1,1,0,1,1,0,0,0,0,1]
print(a)
for i in range(len(a)):
if a[i]==[0]:
print('.', end='')
else:
print('#', end='')
print()
bash:
[0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1]
##############
Upvotes: 0
Views: 3788
Reputation: 601489
You probably want
if a[i] == 0:
instead of
if a[i] == [0]:
You want to compare the items to the integer value 0
, not to the single-element list [0]
.
Upvotes: 3