0

I'm fairly new to python. I've made a hangman-style game that asks users for a name and password and records their score. It then adds these to a file (highscoresUNSORTED.txt). I tried to add all the lines to a list (xList), sort the list and add that back to another file called highscoresSORTED.txt . My code doesn't seem to add anything to the list for some reason, can anyone suggest why?

xList = []

f = open("highscoresUNSORTED.txt", "a+")

f.write("\n" + str(score) + "," + username + "," + password)

for line in f:
    xList.append(line)
    print(xList)

f.close()

xList.sort()
print(xList)

fout = open("highscoresSORTED.txt", "w")
for i in xList:
    fout.write(xList[i] + "\n")
fout.close()
tbysyl
  • 1
  • 1
    [How to debug small programs.](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) What does `xlist` contain? Can you sort what it contains and get the result you want? – Pranav Hosangadi Sep 30 '20 at 18:55
  • xList contains each line of the file as one iteam each. – tbysyl Sep 30 '20 at 18:57
  • I meant for you to ask yourself those questions. The article on [how to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) is a good resource. – Pranav Hosangadi Sep 30 '20 at 18:59

0 Answers0