print('the average rainfall for the months:'for monthvalue in zip(monthsvalues)print(monthvalueprint('the average rainfall for the year:'avgthis code is merely combination of tools and functions that we have already introduced above and in earlier so nothing is truly new notehoweverhow we skip the first line with single call to infile readline()which will simply read the first line and move to the next onethus being ready to read the lines in which we are interested if there are multiple header lines in the file we can simply add multiple readline calls to skip whatever we don' want to process notice also how list slicing is used to remove the yearly data from the lists negative indices in python lists run backwardstarting from the last elementso annual_avg rainfall[- will extract the last value in the rainfall list and assign it to annual_avg the list slicing months[:- ]rainfall[:- will extract all elements from the lists up tobut not including the last onethereby removing the yearly data from both lists writing data to files writing data to files follows the same pattern as reading we open file for writing and typically use for loop to traverse the datawhich we then write to the file using writeoutfile open(filename' ''wfor writing for data in somelistoutfile write(sometext '\ 'outfile close(notice the inclusion of \ in the call to write unlike printa call to write will not by default add line break after each call by defaulsso if we do not add this explicitlythe resulting file will consist of single long line it is often more convenient to have line-structured fileand for this we include the \nwhich adds line break the alternative way of opening files can also be used for writingand it ensures that the file is automatically closedwith open(filename' 'as outfile'wfor writing for data in somelistoutfile write(sometext '\ 'one should use caution when writing to files from python programs if you call open(filename,' 'with filename that does not exista new file will be createdhoweverif file with that name existsit will simply be deleted and replaced by an empty file thereforeeven if we do not actually write