一个文本文件test.txt的一行存储5个整数如下:1 3 56 67 34数之间用空格隔开,要读出这些整数的函数正确的是:
A: def read(): f=open("test.txt","rt") while True: s=f.read() if s!="": print(s) else: break f.close()
B: def read(): f=open("test.txt","rt") while True: s=f.readline() if s!="": print(s) else: break f.close()
C: def read(): f=open("test.txt","rt") st=f.readlines() for s in st: print(s) f.close()
D: def read(): f=open("test.txt","rt") s=f.readline() st=s.splist(" ") for s in st: print(s) f.close()
A: def read(): f=open("test.txt","rt") while True: s=f.read() if s!="": print(s) else: break f.close()
B: def read(): f=open("test.txt","rt") while True: s=f.readline() if s!="": print(s) else: break f.close()
C: def read(): f=open("test.txt","rt") st=f.readlines() for s in st: print(s) f.close()
D: def read(): f=open("test.txt","rt") s=f.readline() st=s.splist(" ") for s in st: print(s) f.close()
举一反三
- 个文本文件test.txt的一行存储5个整数如下:1 3 56 67 34数之间用空格隔开,要读出这些整数的函数正确的是: A: def read():f=open("test.txt","rt")st=f.readlines()for s in st:print(s)f.close() B: def read():f=open("test.txt","rt")while true:s=f.read()if s!="":print(s)else:breakf.close() C: def read():f=open("test.txt","rt")while true:s=f.readline()if s!="":print(s)else:breakf.close() D: def read():f=open("test.txt","rt")s=f.readline()st=s.splist(" ")for s in st:print(s)f.close()
- 下列程序的输出结果是()。f=open("w.txt","w+")f.write("LuxetVeritas")f.seek(7)s=f.read(3)f.close()print(s) A: tas B: Lux C: eri D: Ver
- 文件test.txt的内容是一段文本:hello,与以下代码在同一目录下,程序运行的输出结果是( )。f = open('test.txt')print(f.read(2))f.close( )
- 下列函数能够求n的阶乘n!的是 A: f = lambda n: n! B: def f(n): s=1 for i in range(n): s = s * i return s C: def f(n): s=1 for i in range(n,0,-1): s = s * i return s D: def f(n): if n == 1: return 1 else: return f(n-1)*n
- 有以下程序 f=open(‘file.txt’ , ’a+’) f.write(‘abc’) f.seek(0,0) s=f.read() print(s) f.close() 若文本文件file.txt中原有内容为“hello”,则运行以上程序后,输出为( )