但是我想從最小到最大排序幾個點。 我都希望得到這樣的結果:從最小到最大排序
Drogba 2 pts
Owen 4 pts
Henry 6 pts
然而,我的排名卻似乎恰恰相反,現在:-(
Henry 6 pts
Owen 4 pts
Drogba 2 pts
我想我的問題是我的功能冒泡
?def Bubblesort(name, goal1, point):
swap = True
while swap:
swap = False
for i in range(len(name)-1):
if goal1[i+1] > goal1[i]:
goal1[i], goal1[i+1] = goal1[i+1], goal1[i]
name[i], name[i+1] = name[i+1], name[i]
point[i], point[i + 1] = point[i + 1], point[i]
swap = True
return name, goal1, point
def ranking(name, point):
for i in range(len(name)):
print(name[i], "\t" , point[i], " \t ")
name = ["Henry", "Owen", "Drogba"]
point = [0]*3
goal1 = [68, 52, 46]
gain = [6,4,2]
name, goal1, point = Bubblesort(name, goal1, point )
for i in range(len(name)):
point[i] += gain[i]
ranking (name, point)
如果目標1 [I + 1]>目標1 [I]: - 讓它 '<' – 2017-08-12 14:13:29
總是同樣的問題:-(@ - 阿卜杜拉Alemadi – tamzoro