Solution to Exercise 3 (Day 1, morning session)

One of the entries in not_working.data (number 8 in the second line) contains an additional special character, and Python fails to convert it to an integer using the int function (line 31 in convert_to_dict.py). Python correctly raises an exception, but it is captured in the try … except statement to get_number_dict.

This kind of bug is quite common, and is due to forgetting to handle incorrect input in a function. There are two possible approaches to solving the bug: The first is to detect when the input cannot be converted to integer (e.g., by catching a ValueError around line 31); The second is to raise an appropriate exception. In this second case you should make sure to test that the walk_string function raises the correct exception, but also that get_number_dict does not stop it from being raised.