I am trying to display scores from positions 1 to 10 (most wins). For example:
- Test1 - 5 wins
- Test2 - 4 wins
- Test3 - 2 wins
- N/A
- N/A
etc.
I am using a notepad file which stores usernames, scores and passwords (in order), here's the inside look of it (users.txt):
Test1,5,TestPassword$!14
Yes,63,TestPassword$!3
Ok,35,TestPassword$!152
From here on, I figured out how to replace amount of wins with new but now I have to figure out how to display positions of winners and I've been having a difficult time. I could either try to somehow have scores (split by "," and be known as split[1]) be compared then printed out or order the lines in order of most wins from within the notepad.
Things I tried (mostly from other posts to see as a basic format of which would work best):
position = 0
choice = input("Want to see the leaderboard (Y/N)?")
if choice == "Y":
file = open("users.txt","r")
lines = file.readlines()
for each in lines:
position = position + 1
split = (each.split(","))
print(str(position)+".\n"+"Username:",split[0]+"\nWins:",split[1])
#not for sorting just printing out in order
num_list = []
file = open("users.txt","r")
lines = file.readlines()
for each in lines:
num_list.append(int((each.split(","))[1]))
print(num_list)
print("Max number is -" ,max(num_list))
print("Line number is - ", (num_list.index(max(num_list)))+1)
num_list = []
file = open("users.txt","r")
lines = file.readlines()
for each in lines:
num_list.append(int((each.split(","))[1]))
print(num_list)
max1 = num_list[0]
max2 = num_list[1]
max3 = num_list[2]
for num in num_list:
if num > max1:
max2 = max1
max1 = num
elif num > max2:
max2 = num
print(max1)
print(max2)
nums = [1,151,2,53215,31,593,9192,5128,3818,5,38,3]
new_list = set(nums)
for i in range(10):
high = max(new_list)
new_list.remove(high)
print(max(new_list))
TL;DR display positions from most wins in order of 1 to 10 from notepad file.