+ 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

1st Sep 2018, 8:46 AM
Chen Chee Kin
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
1st Sep 2018, 8:59 AM
Anna
Anna - avatar
+ 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.
1st Sep 2018, 8:55 AM
Anna
Anna - avatar
+ 1
Oh,that's why! Thanks!!
1st Sep 2018, 8:57 AM
Chen Chee Kin