Python: Write array values into file

The for loop will ask i to iterate over the values of an iterable, and you’re providing a single int instead of an iterable object You should iterate over range(0,len(highscores)):

for i in (0,len(highscores))

or better, iterate directly over the array

highscores.append(wins)
# Print sorted highscores print to file
file = open('highscore.txt', 'w') #write to file
file.write('Highscores (number of wins out of 10 games):') 
for line in highscores:
     file.write(line)
file.close() #close file

Leave a Comment