Python help pls

Python help pls
0

iam trying out here to store numbers in the lists… but it shows l[i]=input()
IndexError: list assignment index out of range … at line 4 pls help me out

l=[" "]
print ("enter the numbers")
for i in range(0,6):
    l[i]=input()
print(l)

What are the values of i in your for loop? They’re: 0, 1, 2, 3, 4, & 5. List l only has 1 item, at index 0. So loop starts with l[0] = input() and it asks for numbers, all is well because an item at index 0 exists there already to overwrite.
But on the second round of the loop it tries: l[1] = input(). Well there is no l[1], or l[2], l[3], l[4], l[5] items. You get an IndexError because your referencing an index for a list that doesn’t have that index.

In short, you’re trying to change list items instead of adding an item to the list. Rather than using list assignment, you need to append (add to list) the new inputs to list l every loop:

l.append(input("enter the numbers"))
# or 
l += [input("enter the numbers")]

Also, just FYI there is a Python section of the FCC Forum.

You would also try this

l=[0]*6
print ("enter the numbers")
for i in range(0,6):
    l[i]=input()
print(l)