mercredi 18 novembre 2015

Traceback: list index out of range

def PlayEasy():
    list = []
    filename = 'words.txt'
    with open(filename) as f:
        content = f.readlines()
    list.append(content)
    print(list)
    print(list[0] + list[1] + list[2])
    print(list[3] + list[4] + list[5])
    print(list[6] + list[7] + list[8])

Try to run but get this error message:

Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    PlayEasy()
  File "/home/http://ift.tt/1MAWDW8", line 24, in PlayEasy
    print(list[1] + list[1] + list[2])
IndexError: list index out of range

I'm trying to print out all 9 items of the list in a 3x3 grid.




Aucun commentaire:

Enregistrer un commentaire