QuestionA script to writing to filesUse the template:def append_file_string(file_name, string_of_lines): # Takes two strings, appends the string to the end of the filedef write_file_list(file_name, list_of_lines): # Takes a string and list, writes all items from list to file where each item is one linedef copy_file_add_line_numbers(file_name_read, file_name_write): # Takes two strings, reads data from first file, writes data to new file, adds line number to new fileif __name__ == ‘__main__’: file1 = ‘1.txt’ file2 = ‘2.txt’ file3 = ‘3.txt’ string1 = ‘First LinenSecond LinenThird Linen’ list1 = [‘Line 1’, ‘Line 2’, ‘Line 3’] append_file_string(file1, string1) print(read_file_string(file1)) write_file_list(file2, list1) print(read_file_string(file2)) copy_file_add_line_numbers(file2, file3) print(read_file_string(file3))append_file_string():Takes two string argumentsAppends to the file(Argument 1) all data from the string(Argument 2)write_file_list():Takes two arguments: a string and a listWrites to file(Argument 1) all lines of data found in the list(Argument 2)copy_file_add_line_numbers():Takes two arguments: Both are files path-names (which happen to be strings)Reads all data from first file(Argument 1), and writes all lines into second file(Argument 2) adding line numbersLine numbers should be added to the beginning of each line with a colon next to them(see sample output below for reference)Hint: Use an extra variable for the line numberSample Run 1:rm 1.txt 2.txt 3.txt./lab5b.pyFirst LineSecond LineThird LineLine 1Line 2Line 31:Line 12:Line 23:Line 3Sample Run 2 (run second time):python3 lab5b.pyFirst LineSecond LineThird LineFirst LineSecond LineThird LineLine 1Line 2Line 31:Line 12:Line 23:Line 3Sample Run 3 (with import):import lab5bfile1 = ‘1.txt’file2 = ‘2.txt’file3 = ‘3.txt’string1 = ‘First LinenSecond LinenThird Linen’list1 = [‘Line 1’, ‘Line 2’, ‘Line 3’]lab5b.append_file_string(file1, string1)lab5b.read_file_string(file1)# Will print ‘First LinenSecond LinenThird LinenFirst LinenSecond LinenThird Linen’lab5b.write_file_list(file2, list1)lab5b.read_file_string(file2)# Will print ‘Line 1nLine 2nLine 3n’lab5b.copy_file_add_line_numbers(file2, file3)lab5b.read_file_string(file3)# Will print ‘1:Line 1n2:Line 2n3:Line 3n’Computer ScienceEngineering & TechnologyPython Programming PROG 12423
solved : QuestionA script to writing to filesUse the template:def a
How it works
- Paste your instructions in the instructions box. You can also attach an instructions file
- Select the writer category, deadline, education level and review the instructionsÂ
- Make a payment for the order to be assigned to a writer
- Â Download the paper after the writer uploads itÂ
Will the writer plagiarize my essay?
You will get a plagiarism-free paper and you can get an originality report upon request.
Is this service safe?
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
LET THE PROFESSIONALS WRITE YOUR PAPER!