Python文件基本操作
#随机生成1000个数,并写入文件,每行十个数字;打开读取文件内容,并求出其中的最大值,和所在的位置。import randomfile=open("text.txt","w")num=[]i=0col=0max=-1hang=0lie=0while i<1000: i+=1 num.append(random.randint(1,1000))#print(num)for r in num: col+=1 file.write(str(r) + "\t") if (col)%10==0: file.write("\n") #file.write("\t")file.close()file=open("text.txt","r")for line in file: hang+=1 lie=0 line=line.split() for i in line: lie+=1 if i>max: max=i maxhang=hang maxlie=lieprint(maxhang)print(maxlie)print(max)