用python写出:运动会结束后录入选手分数将分数从大到小输出定义一个 n 代表分数输入 n0n100然后输入 n 个正整数使用冒牌排序从大到小输出排名以及分数。
n = int(input("请输入选手数量:")) scores = [] for i in range(n): score = int(input("请输入第{}个选手的分数:".format(i+1))) scores.append(score)
冒泡排序
for i in range(n-1): for j in range(n-1-i): if scores[j] < scores[j+1]: scores[j], scores[j+1] = scores[j+1], scores[j]
输出排名和分数
print("排名\t分数") for i in range(n): print("{}\t{}".format(i+1, scores[i]))
原文地址: https://www.cveoy.top/t/topic/bIcJ 著作权归作者所有。请勿转载和采集!