what exactly is wrong with my code?
It is using an index that is past the end of the list.
There aren't any comments describing what the code is trying to do so I can't point to a statement that is not doing what it is supposed to as described in the comments.
It would help for reading the code if the indentations were more that one space. Poorly formatted code is hard to read.
What is the index that has the value that is past the end of the list?
Add some print statements that print out the value of the index and the length/size of the list it is being used with.
The print out should should you where the index is wrong for the size of the list.