I have written a program that makes sure each cookie has more than 5 chips before moving on.
However, the line if cookie[i] > 5: seems to be problematic, as it produces a "list index out of range" error. I thought foo = [] created a list with no ending, so I don't get why any number would be out of range in this list. What am I doing wrong?
cookie = []
...
for i in range(0, 11):
if cookie[i] > 5:
break
Try:
len(cookie)
You'll see if you haven't put anything in it that it'll be size 0. With cookie = [] you can continuously add elements to the list but it's initialized empty.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With