Doesn't matter if the spaces are in the file i just cant have them show.
bigscore = str(bigscore)
leaderboard = []
highscore = open("highscore.txt", mode = "r+")
for each in highscore:
leaderboard.append(each.strip())
leaderboard.append(winner)
leaderboard.append(bigscore)
scores = []
for each in range(1, 12):
if each % 2 != 0:
x = int(leaderboard[each])
scores.append(x)
scores.sort()
newleaderboard = []
loser = str(scores[0]).strip()
losernum = leaderboard.index(loser)
leaderboard.pop(losernum)
leaderboard.pop(losernum - 1)
scores.pop(0)
for each in scores:
each = str(each).strip()
sort = leaderboard.index(each)
newleaderboard.insert(0, leaderboard[sort].strip())
newleaderboard.insert(0, leaderboard[sort - 1].strip())
open("highscore.txt", mode = "w")
for each in (newleaderboard):
highscore.write(each.replace(" ", ""))
highscore.write("\n")
print("Here is the new leaderBoard")
for each in newleaderboard:
each.rstrip()
each.strip()
each.lstrip()
each.replace("\x00","")
each.replace(" ","")
print(each.strip())
my code sorts the name and score of players in an external file.
It keeps the name together with the person that gets it and saves to an external file.
However, it adds spaces when i write to the file.
But i do not want to change the way i did it (eg. using a dictionary instead)
It is meant to be my work but i need help on the spaces and the spaces only.
I cant fix it and my teacher cant.
Disclaimer-this is for the new NEA, help from forums online are now allowed, and all credit will be given when i submit it, this was a last resort.