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)
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)
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))
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}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us