Skip to content
Advertisement

How do I fix a ‘ list index out of range’ error?

I’m a beginner programmer currently learning Python and I’m programming a game for the first time.

The name and result of the winner is written to an external file and can be read from and displayed in the form of a table.

However, I am getting an error here:

JavaScript

This is the whole function for reference:

JavaScript

How could I fix this?

Advertisement

Answer

Your file has empty lines, which csv.reader is returning as empty lists. You should skip them when filling in `results.

JavaScript

I used >= 2 because the code that prints the leaderboard requires row[0] and row[1] to be filled in.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement