HiveBrain v1.2.0
Get Started
← Back to all entries
patternpythonMinor

Displaying a leader board from a text file and calculating points

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
leaderfilepointstextdisplayingcalculatingandfromboard

Problem

The text file is laid out like this: first name, last name, wins, losses

dex,kop,5,6

desder,jok,0,11

aslan,vert,11,0

jax,sas,2,9

buy,guy,1,10


Code:

def points():

    template = "|{0:= 1:

                poin = int(data[2]) * 3

                data.append(poin)

                print(template.format(data[0], data[1], data[2], data[3], data[4]),'\n')

        file.close()

points()


The program should only display players that have won at least 1 game and calculate their points, a win is equal to 3 points.

Any suggestions as to how to improve the code any would be great.

Solution

Since you are using all the elements of data, You can turn:

print(template.format(data[0], data[1], data[2], data[3], data[4]))


into this:

print(template.format(*data))


See here for some details.

Code Snippets

print(template.format(data[0], data[1], data[2], data[3], data[4]))
print(template.format(*data))

Context

StackExchange Code Review Q#156231, answer score: 3

Revisions (0)

No revisions yet.