python - 如何计算学生的分数在>25th percentile <75th percentile之间,按照分数的递增顺序。使用下面的函数

标签 python

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/

相关文章:

python - 如何在 BeautifulSoup 中使用 Unicode 结果

python - 使用 Python 生成包含列表中单词的句子生成器

python - incr 如何处理过期时间?

python - 将 Pandas 数据框中具有不同日期的较早行的值连接起来

python - 为什么我会收到此 ImportError?

python - sqlalchemy 不创建我的外键

Python Pygame 使用共享调用时传递参数

python - django 在同一模板中为不同的 for 循环重用 html block

python - PyPDF2 提取空文本 : Python3

python - 查找路径的根