报错‘int‘ object is not callable

错误信息 ‘int’ object is not callable 表示尝试将整数对象当作可调用函数来使用,通常发生在使用函数调用语法时,但实际上在这里不应该使用函数调用语法。

for id in studentid.keys():
    print(id+','+studentid[id],end='')
    score=studentscore[id]
    sum=0
    cnt=0
    for name in coursename:
        print(','+score[name],end='')
        sum+=int(score[name])
        cnt+=1
    print(','+str(int(sum/cnt)))
Python={"Jhon":78,'张三':80}
OOP={"Jhon":82,'张三':80}
军事学={"Jhon":90,'张三':80}
微积分={"Jhon":83,'张三':80}
s=(sum(Python.values())/len(Python),sum(OOP.values())/len(OOP),sum(军事学.values())/len(军事学),sum(微积分.values())/len(微积分))
print(s) 

这段代码中,sum既作为了整型变量,又作为了sum求和函数,两者冲突
解决办法:将上面的sum整型变量修改名称修改为add_sum

for id in studentid.keys():
    print(id+','+studentid[id],end='')
    score=studentscore[id]
    add_sum=0
    cnt=0
    for name in coursename:
        print(','+score[name],end='')
        add_sum+=int(score[name])
        cnt+=1
    print(','+str(int(add_sum/cnt)))
Python={"Jhon":78,'张三':80}
OOP={"Jhon":82,'张三':80}
军事学={"Jhon":90,'张三':80}
微积分={"Jhon":83,'张三':80}
s=(sum(Python.values())/len(Python),sum(OOP.values())/len(OOP),sum(军事学.values())/len(军事学),sum(微积分.values())/len(微积分))
print(s) 

你可能感兴趣的:(Bug,python)