返回顶部

#定义函数,获得字典,姓名是key,科目和成绩是value def get_data(): with open("成绩单.txt","r") as f: head = f.readlines() head[0] = head[0].replace("\n","") #print(head) #print(head[0]) #print(type(head[0])) head_list = head[0].split(",") #print(head_list) score_dict = {} #遍历head中索引从1开始的数据,且去掉换行, #以逗号分隔,存储到data_list for data in head[1:]: #print(data) data = data.replace("\n","") #print(data) data_list = data.split(",") #print(data_list) #获取到head_list中的元素,作为score_dict中的key for i in range(len(head_list)): if i == 0: name = data_list[0] score_dict[name] = {} else: score_dict[name][head_list[i]] = data_list[i] return score_dict #定义函数,进行排名,形参是字典 def get_order(data): #先定义各科成绩的空列表 chinese_list = [] math_list = [] english_list = [] total_list = [] #进行填充数据,通过遍历data中的

5

0/300

评论 1

卓越助教

53行末尾少半边括号

2021-09-06 15:46:24

- 没有更多了 -