按行取数据
f=open("F:\\vsnode\\python\\water.txt","r+",encoding='utf-8') while True: line=f.readline() if not line :break line_list=list(line.split()) if(len(line_list)==0): continue print("账户号为",line_list[0],end=" ") nums=0.0 for i in range(1,len(line_list)): nums+=int(line_list[i]) print("的用户,一年的水费为:",nums*1.05) f.close()