My coding here:

option_input = raw_input(">>>")
option_input = option_input.upper()
if option_input == "V":
    print "High Scores:"
    saveFile = open("scores.txt", 'r')
    scores = saveFile.read()
    saveFile.close()
    nameScore= []
    for line in scores.split('\n'):
        # skip any empty line
        if not line:
            continue
        userScore, score = line.split(',')
        #convert score to a numeric value
        score = int(score)
        nameScore.append((score, userScore))
    print "%-18s %s" % (nameScore, score)

the result still show up :

High Scores:
[(13, 'Matthew'), (6, 'Luke'), (3, 'John'), (3, 'john')] 3

I want to show this up like

13, Matthew
 6, Luke
 3, john

all should be align..
I really looking forward your help :)

Edited 5 Years Ago by vegaseat: added code tags

Maybe something like this:

option_input = raw_input(">>> ").upper()
if option_input == "V":
    print "High Scores:\n"
    saveFile = open("scores.txt", "r")
    scores = saveFile.readlines()
    for line in scores:
        if "," in line:
            userScore, userName = line.split(',')
            print "%2s, %s" % (userScore, userName.strip())

At the end of the program you're assigning the variables wrong and end up creating tuples. You need to have your print statement in the loop to cycle through the lines.

What is wrong with:

print(open("scores.txt").read())

Just save the scores correctly in first place.

Edited 5 Years Ago by pyTony: n/a

This article has been dead for over six months. Start a new discussion instead.