def writeFile(): """write data to a file""" try: myFile = open('new_file.txt', 'w') myFile.write("Little Bo Peep has lost her sheep") myFile.write("\n") myFile.write("And doesn't know where to find them.") myFile.write("\n") myFile.close() except FileNotFoundError: print("Error: The file could not be created.") except IOError: print("Error: There was an issue writing to the file.") finally: print("File operation completed.")