Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
The data reader of the lesson reports each bad line with a message. Change it so that it also counts how many bad lines had each kind of reason, using a dictionary. The kinds are: "not a number", "out of range" and "wrong form".
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. Raise our own error for each kind, with a message that is exactly the kind. Then count the messages with the counting pattern.
Check. By hand: Meera,sixty is not a number. Kabir and the empty line have the wrong form. Ana,140 and Dev,-3 are out of range. So the counts are: wrong form 2, not a number 1, out of range 2.
Answer: {'Asha': 72, 'Tara': 90} and {'not a number': 1, 'wrong form': 2, 'out of range': 2}. The order of the keys follows the order in which the kinds first appeared.
Log in to join the discussion.
Loading…