Auto commit

上级 df352508
with open('D:\python\实验报告\scores.txt','r') as f:
player = [[] for i in range(5)]
name = [[] for j in range(5)]
i = 0
for lines in f:
lines= lines.split(' ')#切割成一个列表
copy_lines= lines.copy()#复制刚切割时的列表,用于后面建立一个名字的列表
del lines[0]#删除第一个元素(名字)
del lines[len(lines)-1]#删除末尾的'\n'
new_lines = list(map(float,lines))#转成floa型
max_sore = max(new_lines)#最高分
min_sore = min(new_lines)#最低分
sore = round((sum(new_lines)-max_sore-min_sore) / 8, 3)#求每个运动员的平均分
name[i].append(copy_lines[0])#将多个类型为list的名字放一个list中【【】,【】,【】】
player[i].append(sore)#将多个类型为list的分数放入一个list中【【】,【】,【】】
i += 1#循环第i名运动员
new_name = []
for v in range(len(name)):
for na in name[v]:
new_name.append(str(na))#将名字转换为str型并将多个列表合并为一个列表【 , , , 】
new_player= []
for k in range(len(player)):
for num in player[k]:
new_player.append((float(num)))#转换为float型并将多个列表合并为一个列表【 , , ,】
# print(new_player,new_name)
new_dict = {}
for m in range(5):
dict = {}
dict.setdefault(new_player[m], new_name[m])#{ : }{ : }{ : }
new_dict.update(dict)#将多个字典合并为一个字典{ : , : , : }
#print(new_dict)#{ : , : , : }
new_player.sort(reverse=True)#以运动员的分数进行排序
for y in range(5):
print(f'第{y+1}名:{new_dict[new_player[y]]} 平均分:{new_player[y]}')#根据字典,以运动员的分数来找到运动员的名字
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册