题目
题目

Fal25_CS003C_74229 Ch. 7 Pre-Quiz (Remotely Proctored)

单项选择题

The following code segment is supposed to read all of the lines from test.txt and save them in copy.txt. infile = open("test.txt", "r") outfile = open("copy.txt", "w") line = infile.readline() ____________________ outfile.write(line) line = infile.readline() infile.close() outfile.close() Which line of code should be placed in the blank to achieve this goal?

选项
A.while line != "\n" :
B.while line == "\n" :
C.while line != "" :
D.while line == "" :
查看解析

查看解析

标准答案
Please login to view
思路分析
We need to determine which line properly completes the loop to read all lines from test.txt and write them to copy.txt. Option 1: while line != "\n" : This would stop when the line is just a newline character. If a line contains actual content, including the trailing newline, this condition remains true, but many lines end with a newline and not with a solitary newline string; als......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!