答案:利用冒泡排序完成!??!
name = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
score = [89, 72, 88, 79, 99]
for i in range(len(score) - 1) :
? ? for j in range(len(score) - i - 1) :
? ? ? ? if score[j] < score[j + 1] :?
? ? ? ? ? ? score[j], score[j + 1] =? score[j + 1] ,score[j]
? ? ? ? ? ? name[j], name[j + 1] =? name[j + 1] ,name[j]
? ? ? ? ? ??
print(name)
2021-06-21
感覺各位都想復(fù)雜了,各種秀,這個(gè)案例只是展示list的元素替換而已
2021-03-12
# Enter a code
# coding:utf-8
names = ['Alice', 'Bob', 'Candy', 'David', 'Ellena']
scores = [89, 72, 88, 79, 99]
templateNames = []
templateScores = [89, 72, 88, 79, 99]
scores.sort(reverse=True)
print("降序排列后的成績:" + str(scores))
index_Score = 0
index_TemplateScore = 0
for score in scores:
? ? index_TemplateScore = 0
? ? for templateScore in templateScores:
? ? ? ? if score == templateScore:
? ? ? ? ? ? templateNames.append(names[index_TemplateScore])
? ? ? ? index_TemplateScore += 1
print("排列后的名字:" + str(templateNames))
2021-02-10
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
print(s1 & s2)