Answers for "leaderboard in python"

0

how to make a leaderboard in python

# leaderboard = []
f = open('Leaderboard.txt', 'r')
leaderboard = [line.replace('\n','') for line in f.readlines()]


for i in leaderboard:
    print(i)
Posted by: Guest on July-09-2020
0

leaderboard in python

#append the name and score to the file, in the format:
#"(name) + (score) + \n"
f = open("top_scores", "a")
f.write(player1 + " " + str(player1_score) + "\n")
f.write(player2 + " " + str(player2_score) + "\n")
f.close()

#this outputs the name and score from the file in order of highest score to lowest
file = open('top_scores').readlines()
scores_tuples = []
for line in file:
    name, score = line.split()[0], line.split()[1]
    scores_tuples.append((name, score))
scores_tuples.sort(key=lambda t: t[1], reverse=True)
print("\n\n\tHigh Scores\n")
for i, (name, score) in enumerate(scores_tuples[:5]):
    print("Player: {} - Score: {} ".format(name, score))
Posted by: Guest on June-12-2021
0

how to create a leaderboard on python 3.8.1

myList = {"person1": 1, "person2": 1, "person3": 1}
myList["person2"] += 30
print(myList)
# {'person1': 1, 'person2': 31, 'person3': 1}
Posted by: Guest on July-09-2020

Python Answers by Framework

Browse Popular Code Answers by Language