python - Creating an empty list to have data assigned afterwards -
lets want create list of names
listofnames = []
then have while loop such as
count = 0 while listofnames[count] < 10: namelist[count] = raw_input("enter name: ") count += 1
python says list index out of range, list index should @ 0, correct?
how add list each time while loop ran? i'm assuming wrong list assignment.
an empty list doesn't have index yet, it's empty list! if want fill it, have :
while count < 10: namelist.append(raw_input("enter name: ")) count += 1
this way, condition evaluated , append method, able add new items in list.
there few advanced tricks easily, considering level, think it's better understand code before moving on.
Comments
Post a Comment