+ 3
Python
i=0 row1=['0,0,0'] print(row1) z = input("Y/N").upper() if i<5: if z =="Y": row1[i]=1 print(row1) i+=1 I was expecting the output to be [1,0,0] Why the output for the if statement is only [1], where did the other 2 two "0" went? Thanks in advance
3 odpowiedzi
+ 4
You're welcome. Also, I think a while loop might be what you're looking for:
i = 0
row1 = [0,0,0]
print(row1)
while i < len(row1): # make sure you don't get an IndexError
if input("Y/N").upper() == 'Y':
row1[i] = 1
print(row1)
i += 1
+ 3
row1=['0,0,0'] defines a list with one element: the string '0,0,0'.
If you want a list with thee zeros, remove the qutation marks.
+ 1
Oh,that's why! Thanks!!