[Python] Matplotlib and "List index out of range" error

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    i'm trying to create a graph of my AI score in a Breakout clone and I struggle with a "List index out of range" error. My code :

    import matplotlib.pyplot as plt

    x = []
    y = []

    for line in open('scores.txt', 'r'):
    lines = [i for i in line.split()]
    x.append(lines[0])
    y.append(int(lines[1]))

    plt.title("BrealAI Performance Evolution")
    plt.xlabel("Number of games")
    plt.ylabel("Score")
    plt.yticks(y)
    plt.plot(x, y, marker = 'o', c = 'g')

    plt.show()


    Here, "y.append(int(lines[1]))" is the problem. Please help me

    I tried to change int to sys.maxint.

    Continue reading...

Compartilhe esta Página