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 =
    nameScore= []
    for line in scores.split('\n'):
        # skip any empty line
        if not line:
        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 :)

Recommended Answers

All 3 Replies

There are different ways to do it. Here is one

>>> for score, name in nameScore:
...  print "{0}, {1}".format(score, name)
13, Matthew
6, Luke
3, John
3, john

Also, use code tags when you post python code. See here

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:


Just save the scores correctly in first place.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.