Students=['student1','student2','student3','student4','student5','student6','student7','student8','student9','student10']
Marks = [45, 78, 12, 14, 48, 43, 47, 98, 35, 80]
def display_dash_board(students, marks):
dictionary = dict(zip(Students,Marks))
# write code for computing top top 5 students
print("Top 5 Students are :\n\n")
for key, value in sorted(dictionary.items(), key=lambda item: item[1],reverse=True)[:5]:
print("%s: %s" % (key, value))
# write code for computing top least 5 students
print("\n\n Top Least 5 Students are : \n\n")
for key, value in sorted(dictionary.items(), key=lambda item: item[1])[:5]:
print("%s: %s" % (key, value))
# write code for students within 25 to 75 percentile
print("\n\n Students in 25-75 percentile range are : \n\n")
用于计算百分位使用:-
max = max_mark
min = min_mark
diff = max - min
pre_25 = diff*0.25
pre_75 = diff*0.75
display_dash_board(学生,分数)
最佳答案
给出执行百分位数计算的提示,
max_mark = max(marks)
min_mark = min(marks)
diff = max_mark - min_mark
pre_25 = diff * 0.25
pre_75 = diff * 0.75
然后您可以过滤您的字典以仅匹配这些限制的分数,
within_25_75 = {
name: score
for (name, score)
in dictionary.items()
if pre_25 <= score <= pre_75
}
然后像以前一样打印它们。
关于python - 如何计算学生的分数在>25th percentile <75th percentile之间,按照分数的递增顺序。使用下面的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61997679/