I am making a high-score module, which currently only shows the top 5 scores achieved, i want to be able to show these scores as i am currently but also show them with the name that is associated with that score, how would i do this?
This is my code so far:
def highscore():
file_highscore = open('scores_test2.txt' , 'r')
scores_and_names = []
scores = []
scores_2 = []
names = []
for line in file_highscore.readlines():
score_info = line.split()
scores_and_names.append(line)
scores_2.append(scores_and_names[line][])
scores.append(score_info[1])
names.append(score_info[0])
scores.sort(key = int)
scores.sort(reverse = True)
print('The First 5 Highscores are:')
for item in scores[:5]:
print(item)
Any help would be much appreciated as I need to use this code for a school assignment.