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')
srinivasa reddy_1 0 Newbie Poster
woooee 814 Nearly a Posting Maven
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.