patternpythonMinor
Displaying a leader board from a text file and calculating points
Viewed 0 times
leaderfilepointstextdisplayingcalculatingandfromboard
Problem
The text file is laid out like this: first name, last name, wins, losses
Code:
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.
dex,kop,5,6
desder,jok,0,11
aslan,vert,11,0
jax,sas,2,9
buy,guy,1,10Code:
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
into this:
See here for some details.
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.