2021年5月1日星期六

Iterate through Inner Dictionaries in Python

im a beginner in Python. im practicing a use case to get the final score of the student that are stored in dictionaries. COuld you please guide me is there a way to simplify this?

 ScoreCard = {'Antony':{'maths':99,'english':33, 'science':100},'Jeff':{'maths':45,'english':99, 'science':73},          'Mark':{'maths':77,'english':80, 'science':86}}    def sumofMarks(MarkList):      SumMark = 0      for k, v in MarkList.items():          SumMark = SumMark + v      return SumMark            def getMarks(Score, student):      for k,v in Score.items():          if student in Score.keys():              newdic = Score[student]              finalScore = sumofMarks(newdic)              print("Final Score of:", student)              return finalScore          else:              print("Student Not found in registry !")              break                getMarks(ScoreCard,'Jeff')  
https://stackoverflow.com/questions/67352397/iterate-through-inner-dictionaries-in-python May 02, 2021 at 10:05AM

没有评论:

发表评论