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] 
A.
import pickle f = open("output.dat", "w") pickle.dump(course_no, f) pickle.dump(score_rec, f) f.close()
B.
import pickle f = open("output.dat", "wb") f.write(course_no) f.write(score_rec) f.close()
C.
import pickle f = open("output.dat", "wb") pickle.dump(course_no, f) pickle.dump(score_rec, f) f.close()
D.
import pickle f = open("output.dat", "wb") pickle.load(course_no, f) pickle.load(score_rec, f) f.close()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!