This should store [1,2,3,4,5] in the list but it stores [1,1,1,1,1] instead:
l=[0]*5
for x in range(5):
y=1
l[x] = y
y+=1
print (l)
This should store [1,2,3,4,5] in the list but it stores [1,1,1,1,1] instead:
l=[0]*5
for x in range(5):
y=1
l[x] = y
y+=1
print (l)
you must place y = 1
before entering the for
loop:
my_list = [0] * 5
y = 1
for x in range(5):
my_list[x] = y
y += 1
print(my_list)
I changed the name of your list to my_list
; using l
is a source of confusion with 1
...