如何从嵌套列表中获取每个列表的平均成绩?

时间:2018-09-06 20:52:26

标签: python python-3.x

我目前收到一条"TypeError: unsupported operand type(s) for +: 'int' and 'str' "消息。这是我的代码

def studentGrades(gradeList):
    avgGrades = [ ]
    for element in gradeList:
        isinstance(element, int)
        i = 0
        for j in element:
            i = i + j
        average = (sum(element) / len(element))
        avgGrades.append(average)
    return avgGrades

1 个答案:

答案 0 :(得分:0)

看起来您只需要将j转换为int即可,如下所示:

for j in element:

    i = i + int(j)