I have a list in this format: 1st name, last name, wins, losses
alex,kop,5,6
derex,mop,0,11
sas,hot,11,0
rich,john,2,9
jeremy,cane,1,10
My program displays the data from the text file in a leader board only showing players that have won at least 1 game and then calculates their points by multiplying their wins by 3. Here's my code.
def points():
template = "|{0:<30}|{1:<30}|{2:<30}|{3:<30}|{4:<30}"
header = template.format("1st name: ","2nd Name: ", "won: ", "lost: ","points: ")
print(header)
with open(r'prac2.txt', 'r') as file:
for line in file:
data = line.strip().split(',')
if int(data[2]) >= 1:
points = int(data[2]) * 3
data.append(points)
print(template.format(*data),'\n')
I want to sort the leader board from highest amount of points to lowest amount but i have no idea how.