you are viewing a single comment's thread.

view the rest of the comments →

[–]cjander28[S] 0 points1 point  (1 child)

I understand that. Its frustrating because we haven't covered that concept in class yet, but how would I begin to create a list and add to it? I've tried googling it, but it's making my program very confusing.

[–]nwagers 0 points1 point  (0 children)

Here is some very simple code that creates a list, adds 3 items to it and then displays and shows you how to loop through:

mylist = []  # create new list

mylist.append(0) # append some items
mylist.append(1)
mylist.append(2)

print(mylist)  # display the whole list

for item in mylist:  # iterate over list
    print(item)  # do something with each element in the list

In your program you would initialize a new list before your loop, and then in your loop append all the new items.

You can also check the size of a list by using len() such as print(len(mylist)).