Dictionary
Dictionary
Program 8.44:
Write a program that has dictionary of names of
students and a list of their marks in 4 subjects. Create
another dictionary from this dictionary that has the
names of the students and their total marks. Find out
the topper and his/her score.
Python Code
marks = {'Neha': [97, 89, 94, 90], 'Mitul': [92, 91, 94, 87], 'Shefali': [67, 99, 88, 90]}
print("The marks of each student is:", marks)
total = 0
new_marks = {}
for i in marks:
b = marks[i]
for j in b:
total = total + j
new_marks[i] = total
total = 0
print("The total marks of each student: ", new_marks)
maxvalue = max(new_marks.values())
maxkey = max(new_marks, key=new_marks.get)
print("The topper of the class is", maxkey, "with total mark", maxvalue)
Output
The mark of each student is: {'Neha': [97, 89, 94, 90],
'Mitul': [92, 91, 94, 87], 'Shefali': [67, 99, 88, 90]}
The total marks of each student: {'Neha': 370, 'Mitul': 364,
'Shefali': 344}
The topper of the class is Neha with total mark 370.
Exercise 11:
Output:
Please enter your string: apple
The string in alphabetical order is: ['a', 'e', 'l', 'p']
The frequency of each letter: {'a': 1, 'e': 1, 'l': 1, 'p': 2}