class subjectGradeBook(object):

    def __init__(self):

        self.grades={}

    def addStudents(self,name):

        self.grades[name]={}

    def reportGrade(self,name,subject,grade):

        k=self.grades[name]

        gradeList=k.setdefault(subject,[])

        gradeList.append(grade)

    def averageGrade(self,name):

       k=self.grades[name]

       total,count=0,0

       for grades in k.values():

           total+=sum(k)

           count+=len(k)

       return total/count

book    =   subjectGradeBook()

book.addStudents('AlbertEinstein')

book.reportGrade('AlbertEinstein',  'Math', 75) 

book.reportGrade('AlbertEinstein',  'Math', 65)

book.reportGrade('AlbertEinstein',  'Gym',  90)

book.reportGrade('AlbertEinstein',  'Gym',  95) 

book.averageGrade('AlbertEinstein')

k is a dictionary value for the Albert Einstien key self.grades[name] so you are trying to sum/add a dictionary total+=sum(k). I would suggest that you print "grades" so you at least know what it contains.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.