我怎么能算每个年级的每个类别中的金额为一组标记

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我怎么能算每个年级的每个类别中的金额为一组标记相关的知识,希望对你有一定的参考价值。

我在给定一组商标

midtermMarks = [48.0, 64.25, 71.80, 82.0, 53.45, 59.75, 62.80, 26.5,
55.0, 67.5, 70.25, 52.45, 66.25, 94.0, 65.5, 34.5, 69.25, 52.0]

我必须找到多少个A的。 B的,和C的有在该组中,假定A是100-80 B是79-70,C是69-60

答案

首先,你需要创建具有密钥'60字典-70' ,'70 -80' 和'80 -100' 为0的每个值并使用循环获取每个标记和使用if语句检查每一个条件,如果条件满足再加入1到相应的键。

我做给你。希望它的工作原理。

[码]

import pprint     # This module prints dictionary in a pretty way

marks = [48.0, 64.25, 71.80, 82.0, 53.45, 59.75, 62.80, 26.5,
     55.0, 67.5, 70.25, 52.45, 66.25, 94.0, 65.5, 34.5, 69.25, 52.0]

counting = 'Number of A\'s': 0, 'Number of B\'s': 0, 'Number of C\'s': 0  # Dictionary to count the number in given range

for mark in marks:  # Getting each marks from marks list
    if mark >= 80:  # Checking if mark is more than 80
        counting['Number of A\'s'] += 1  # Adding 1 if there is repetition to dictionary

    elif mark >= 70 and mark < 80:  # Checking if mark is more than and equals to 70 but less than 80
        counting['Number of B\'s'] += 1  # Adding 1 if there is repetition to dictionary

    elif mark >= 60 and mark < 70:  # Checking if mark is more than and equals to 60 but less than 70
        counting['Number of C\'s'] += 1  # Adding 1 if there is repetition to dictionary

pprint.pprint(counting)    # Printing the output

[OUTPUT]

"Number of A's": 2, "Number of B's": 2, "Number of C's": 6

以上是关于我怎么能算每个年级的每个类别中的金额为一组标记的主要内容,如果未能解决你的问题,请参考以下文章

标签估计(监督学习)

多类别分类 - 为每个类别使用一组不同的负样本是个好主意?

归并排序

python:总结每个类别的最后一个和最大的单元格

模型数据库中的异构类型

TypeScript 源码详细解读语法1-语法树