Consider an ongoing test cricket series. Following are the names of the players and their scores in the test1 and 2.
Test Match 1 :
Dhoni : 56 , Balaji : 94
Test Match 2 :
Balaji : 80 , Dravid : 105
Calculate the highest number of runs scored by an individual cricketer in both of the matches. Create a python function Max_Score (M) that reads a dictionary M that recognizes the player with the highest total score. This function will return ( Top player , Total Score ) . You can consider the Top player as String who is the highest scorer and Top score as Integer .
Input : Max_Score({‘test1’:{‘Dhoni’:56, ‘Balaji : 85}, ‘test2’:{‘Dhoni’ 87, ‘Balaji’’:200}}) Output : (‘Balaji ‘ , 200)
M = {"test1": {'Dhoni': 56, "Balaji": 85}, 'test2': {'Dhoni': 87, 'Balaji': 200}}
def Max_Score(d):
total = {}
for k in d.keys():
for n in d[k].keys():
if n in total.keys():
total[n] = total[n] + d[k][n]
else:
total[n] = d[k][n]
print("Total Run Scored by Each Playes in 2 Tests: ")
print(total)
print("Player With highest score")
maxtotal = -1
for n in total.keys():
if total[n] > maxtotal:
maxname = n
maxtotal = total[n]
return (maxname, maxtotal)
summary = Max_Score(M)
print(summary)
Comments
Leave a comment