Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a function above_mean(marks) for a dictionary of name and mark. It gives back a sorted list of the names whose mark is more than the mean. For an empty dictionary it gives back an empty list. Test it with {"Asha": 90, "Ravi": 50, "Meera": 70}, with equal marks {"a": 5, "b": 5}, and with {}.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Find the mean first, guarding the empty case. Then collect the names that pass the test.
Check.
["Asha"].[].[] at once, before it can divide by zero.Answer: ['Asha'], [] and [].
Log in to join the discussion.
Loading…