我已经编写了这段代码,我希望它能够组织玩家得分。
file = open("leaderboard.txt", "a")
file.write(str(winnerscore)+ ": " + winner + "\n")
file.close()
fileReading = open("leaderboard.txt","r")
lines = fileReading.read()
fileReading.close()
lines = lines.split("\n")
for line in lines:
print(line)
def bubbleSort(arr):
n = len(arr)
for i in range(n-1):
for j in range(0, n-i-1):
if arr[j] > arr[j+1] :
arr[j], arr[j+1] = arr[j+1], arr[j]
# Driver code to test above
arr = int(float(lines[0]))
bubbleSort(arr)
print ("Sorted array is:")
for i in range(len(arr)):
print ("%s" %arr[i])
它产生这个但不对其进行排序:
76: Daniel
36: Gabriel
30: Perry
92: Avi
28: Yehuda
46: Jeremy
54: Mordechai
96: Paul
80: Pauline
72: Fran
不幸的是,它出现了这个错误信息:
arr = int(float(lines[0]))
ValueError: could not convert string to float: '76: Daniel'
How do I fix this so it sorts from highest score to lowest score?
我该怎么做才能对列表中的分数进行排序?
犯罪嫌疑人X
MYYA
慕侠2389804
LEATH
相关分类