user input and error handling any data to the filesimply opening it for reading will erase all its contents safer way to write to files is to use 'open(filename,' ')which will append data to the end of the file if it already existsand create new file if it does not exist for concrete exampleconsider the task of writing information from nested list to file we have following the nested list (rows and columns)data [ - - ] - - ][- - ][- - ]to write these data to file in tabular formwe follow the steps outlined above and use nested for loop (one for loop inside anotherto traverse the list and write the data the following code will do the trickwith open('tmp_table dat'' 'as outfilefor row in datafor column in rowoutfile write( '{column: }'outfile write('\ 'the resulting file looks like - - - - - - - - the nicely aligned columns are caused by the format specifier given to the fstring in the write call the code will work fine without the format specifierbut the columns will not be alignedand we also need to add space after every number orotherwiseeach line will just be long string of numbers that are difficult to separate the structure of the nested for loop is also worth stepping through in the code above the innermost loop traverses each rowwriting the numbers one by one to the file when this inner loop is done the program moves to the next line (outfile write('\ '))which writes linebreak to the file to end the line after this lineone pass of the outer for loop is finished and the program moves to the next iteration and the next line in the table the code for writing each number belongs inside the innermost loopwhereas the code for writing the line break is in the outer loopsince we only want one line break for each line handling errors in programs as demonstrated aboveallowing user input in our programs will often introduce errorsandas our programs grow in complexitythere can be multiple