user input and error handling average rainfall (in mmin rome months between and jan feb mar apr may jun jul aug sep oct nov dec year although this data file is very smallit is fairly typical example oftenthere are one or more header lines with information that we are not really interested in processingand the remainder of the lines contain mix of text and numbers how can we read such filethe key to processing each line is to use split to separate the two words andfor instancestore them in two separate lists for later processingmonths [values [for line in infilewords line split(split into words months append(words[ ]values append(float(words[ ])these stepsinvolving for loop and then split to process each linewill be the fundamental recipe for all file processing throughout this book it is important to understand these steps properly and well worth spending some time reading small data files and playing around with split to become familiar with its use to write the complete program for reading the rainfall datawe must also account for the header line and the fact that the last line contains data of different type the complete code could look likedef extract_data(filename)infile open(filename' 'infile readline(skip the first line months [rainfall [for line in infilewords line split(#words[ ]monthwords[ ]rainfall months append(words[ ]rainfall append(float(words[ ])infile close(months months[:- drop the "yearentry annual_avg rainfall[- store the annual average rainfall rainfall[:- redefine to contain monthly data return monthsrainfallannual_avg monthsvaluesavg extract_data('rainfall txt'