小编mad*_*hur的帖子

Python:如何检查对象的键值对的数据类型?

我正在创建一个函数来在对象(student1)中添加每个数组(作业,测验,测试)的标记.当代码试图添加"Lloyd"时肯定会出现错误.我要检查的数据类型的"名",以进行算术运算仅当的的关键是数量.请建议.

student1 = {
    "name": "Lloyd",
    "homework": [90, 97, 75, 92],
    "quiz": [88, 40, 94],
    "test": [75, 90]
}    

def eachSubjAverage(std):             
    for item in std:                        
        total = sum(std[item])   #totalling each marks
        std[item].append(total)     

        average_no = total/(len(std[item])-1) #averaging the marks
        std[item].append(average_no) 

eachSubjAverage(student1)
Run Code Online (Sandbox Code Playgroud)

python types arithmetic-expressions object

1
推荐指数
1
解决办法
3843
查看次数

标签 统计

arithmetic-expressions ×1

object ×1

python ×1

types ×1