In this test, each numbered part earns credit separately fro…
Questions
In this test, eаch numbered pаrt eаrns credit separately frоm the оthers. We have a data file that cоntains data in a number of rows. Each row is expected to be made of 2 items separated by a tab.First item is an int number representing age, and second item is a social security number.Here's an example:45 123-45-6789 We need to read the data into a python dictionary list, then do some clean up and plot the data. Write code as detailed below. Your code must follows the specs and restrictions shown below to be valid. 1. In the main function: (5 points) ask the user for a file name. pass the filename to a function that will return a list of dictionary items. This function will return a global counter. If the counter is not 0, print the number of errors shown in that counter. Reset the counter back to 0. This counter is a global variable. the dictionary list is then passed to a function that creates a plot objects list. The plot objects list is is then passed to another function to save each object into a file. if no runtime error occurs from the above, print a success message, else print an error msg. 2. The function to read the data, will receive a file name then reads the data from the file one line at a time. (5 points) For the sake of this function you are only allowed to import the regular expression module we learned about. No other import is allowed. Once one line has been read into your code, using a regex expression, collect the social security number (SSN), this will be the key. If the SSN is unique, create an entry in the dictionary list being created, where the SSN is the key and a list follows that contains the age we just read from that line. Otherwise, if the SSN is not unique, add the age to the list of ages of the current line. For example, if 123-45-6789 appears in the file twice, the dictionary entry should be '123-45-6789':[24 , 56] where 24 is the age of the first time we read that SSN and 56 is the age of the second time we read that SSN. Once all lines have been processed, return the dictionary list. If an entry has an invalid data such SSN or the integer value is not int or negative, then count by 1. The counter should be a global variable. return the dictionary list at the end. 3. Once we obtain the dictionary list from the function of the step above, the data will be passed to the plotting function which creates plots as follows: (5 points) Using matplotlib, create a line plot where the SSN is the x-axis, and the y-axis is the max age of the list of each SSN. Save this object into a plot list that we will return later. Next create a piechart using matplotlib. The segments represent how many SSN's max age falls into 0-25, 26-40, 40-60, 60-120. Note this function uses the max of the age list. Do not repeat the code that calculates the max of each SSN. Instead write a function that returns that value for use in both plots. return the plot object list. 4. The plotting function will return a list of plots to main. The main function will pass them to another function that processes the plot list as follows: (5 points) Ask the user for a filename for each plot, then save the plot object in the list with that filename. Repeat the above for every object in the list.