Feb-11-2019, 05:55 PM
So me and my friend came up with this as a leaderboard system and im wondering are there any improvements that can be made to it? especially in the sorting section?
#prototype leaderboards
import csv
score=input("whats ya score")
username=input("whats ya name")
with open ("protleader.csv", "a", newline='') as file:
fields=['score', 'name']
writer=csv.DictWriter(file, fieldnames=fields)
writer.writerow({'score' : score, 'name' : username})
with open ("protleader.csv", "r") as file:
sortlist=[]
reader=csv.reader(file)
for i in reader:
sortlist.append(i)
for i in range(len(sortlist)):
if i != 0:
sortlist[i][0]=int(sortlist[i][int(0)])
print("")
print("Unsorted:")
for i in range(len(sortlist)):
print(sortlist[i])
for i in range(555):
for i in range(len(sortlist)-1):
if i != 0:
if sortlist[i][0] < sortlist[i+1][0]:
change=sortlist[i]
sortlist[i]=sortlist[i+1]
sortlist[i+1]=change
print("")
print("Sorted and cut:")
for i in range(len(sortlist)-1):
print(sortlist[i])
