1# leaderboard = []
2f = open('Leaderboard.txt', 'r')
3leaderboard = [line.replace('\n','') for line in f.readlines()]
4
5
6for i in leaderboard:
7 print(i)
1#append the name and score to the file, in the format:
2#"(name) + (score) + \n"
3f = open("top_scores", "a")
4f.write(player1 + " " + str(player1_score) + "\n")
5f.write(player2 + " " + str(player2_score) + "\n")
6f.close()
7
8#this outputs the name and score from the file in order of highest score to lowest
9file = open('top_scores').readlines()
10scores_tuples = []
11for line in file:
12 name, score = line.split()[0], line.split()[1]
13 scores_tuples.append((name, score))
14scores_tuples.sort(key=lambda t: t[1], reverse=True)
15print("\n\n\tHigh Scores\n")
16for i, (name, score) in enumerate(scores_tuples[:5]):
17 print("Player: {} - Score: {} ".format(name, score))
1myList = {"person1": 1, "person2": 1, "person3": 1}
2myList["person2"] += 30
3print(myList)
4# {'person1': 1, 'person2': 31, 'person3': 1}
5