Question: Which of the following code will create the output.txt file to have exactly the same contents as the input.txt file? A. out_file = open(output.txt, w)
Which of the following code will create the output.txt file to have exactly the same contents as the input.txt file?
| A. | out_file = open("output.txt", "w") in_file = open("input.txt", "r") for line in in_file: out_file.write(line[:-1]) in_file.close() out_file.close() | |||||||||||||
| B. | out_file = open("output.txt", "w") in_file = open("input.txt", "r") for line in in_file: print(line, file=out_file) in_file.close() out_file.close() | |||||||||||||
| C. | out_file = open("output.txt", "w") in_file = open("input.txt", "r") out_file.writelines(in_file.readlines()) | |||||||||||||
| D. | with open("output.txt", "w") as out_file: for line in open("input.txt", "r"): out_file.writelines(line)
Give the following two variables, which of the following code should be used to write the two variables to a data file, so that they may be easily read out? course_no = 521 score_rec = [10, 9, 10]
|
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
