There is a list with nested dictionaries.
GRADEBOOK = [ {'name':'Maksim Fedartsou', 'subjects': {'math':9,'language':5,'history':8,'foreignl':9}}, {'name':'Pavel Bobkou', 'subjects': {'math':3,'language':8,'history':4,'foreignl':9}}, {'name':'Ann Sokolova', 'subjects': {'math':10,'language':8,'history':4,'foreignl':8}} ] First, I get the values for each student, after which I get in which order these grades are written to the out list.
I want to do the following with the grade for each student: the one that the student received at the exam * 0.7 and add the marks of all the other students for the same subject.
The problem is that I did and it works only for the first student, but he doesn’t go on working, or rather, he thinks that everything is over.
Here is the code with comments:
GRADEBOOK = [ {'name':'Maksim Fedartsou', 'subjects': {'math':9,'language':5,'history':8,'foreignl':9}}, {'name':'Pavel Bobkou', 'subjects': {'math':3,'language':8,'history':4,'foreignl':9}}, {'name':'Ann Sokolova', 'subjects': {'math':10,'language':8,'history':4,'foreignl':8}} ] out= [] for l in range( len( GRADEBOOK ) ): b = [ i for i in GRADEBOOK[l]['subjects'].values() ] out.append( b ) kl = GRADEBOOK[0]['subjects'].keys() mark = 0 marks = [] for n in range(4): # B out я вывел оценки студентов,здесь они должны посчитаться для рейтинговой, то есть для каждого for i in out: #Студента 4 оценки, сколько и предметов, но почему он считает только для одного первого студента, if mark==0:#u как сделать чтоб считал для всех дальше mark= i[n]*0.7 else: mark+= i[n] marks.append( mark )#этот список должен содержать вложенные списки с рейтинговыми оценками для студентов mark = 0 print( marks )