赞
踩
有一个班若干个学生考试的成绩表,由学号和成绩组成,将其组成一个字典如: {'1001':85,'1002':70,'1003':100,'1005':60,'1008':100}。
输出内容:
1. 按成绩从高到低输出成绩表字典;
2. 计算全班的平均分(精确到小数后两位);
3. 输出最高分的同学:学号:成绩。
按字典格式输入
输出成绩表字典、输出平均分、输出最高分。
{'1001':85,'1002':70,'1003':100,'1005':60,'1008':100}
- {'1003': 100, '1008': 100, '1001': 85, '1002': 70, '1005': 60}
- 平均分=83.00
- 最高分:
- 1003:100
- 1008:100
- grade = eval(input())
- grades = []
- ID = []
- for i in grade:
- grades.append(grade[i])
- ID.append(i)
- for i in range(0,len(grades)):
- for j in range(i,len(grades)):
- if grades[j] > grades[i]:
- g = grades[i]
- id = ID[i]
- grades[i] = grades[j]
- ID[i] = ID[j]
- grades[j] = g
- ID[j] = id
- print("{",end="")
- for i in range(0,len(grades)-1):
- print("'{}': {}, ".format(ID[i],grades[i]),end = "")
- print("'{}': {}".format(ID[len(grades)-1],grades[len(grades)-1]),end="")
- print("}")
- sum = 0
- for k in range(len(grades)):
- sum = sum + grades[k]
- average = sum /len(grades)
- print("平均分={:.2f}".format(average))
- highest = grades[0]
- print("最高分:")
- for k in range(len(grades)):
- if grades[k] == highest:
- print("{}:{}".format(ID[k],grades[k]))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。