写出程序的运行结果。s=0fo=open("file.txt","w+")for i in range(1,10): fo.write(str(i))fo.seek(0)ls=fo.read()fo.close()for x in ls: s+=int(x) if int(x)%2 else 0print("输出:{:d}".format(s))
举一反三
- 以下程序的输出结果是: fo = open(“texttxt”,‘w+’) x,y =‘this is a test’,‘hello’ fo.write(’{}+{} ’format(x,y)) print(fo.read()) fo.close()
- 以下程序:fname = input("请输入要写入的文件: ")fo = open(fname, "w+")ls = ["唐诗", "宋词", "元曲"]fo.writelines(ls) fo.seek(0)for line in fo: print(line)fo.close()下面语句中"W+"的含义是( ) fo = open(fname, "w+") A: 文件以覆盖写模式 B: 创建模式 C: 文件以覆盖写模式与r/x/a一同使用 D: r/x/a模式
- 以下程序的输出结果是:( )fo = open("text.txt",'w+')x,y ='this is a test','hello'fo.write('{}+{}\n'.format(x,y))print(fo.read())fo.close() A: this is a test hello B: this is a test C: this is a test,hello. D: this is a test+hello
- fname = input(”请输入要写入的文件:”) fo = open(fname,”w+”) ls = [“唐诗”,”宋词” ,”元曲”] fo.writlines ( ls ) for line in fo: print ( line ) fo.close( ) 上述代码的运行结果为:( )
- 关于下面代码中的变量x,以下选项中描述正确的是。 fo = open(fname, "r") for x in fo: print(x) fo.close()